Skip to content

Commit

Permalink
nextcloud to webdav
Browse files Browse the repository at this point in the history
  • Loading branch information
manzari authored and MichaIng committed Mar 25, 2022
1 parent 05318b1 commit a72e8b3
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions motioneye/uploadservices.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from base64 import b64encode
import datetime
import ftplib
import io
Expand All @@ -27,6 +26,7 @@
import urllib.error
import urllib.parse
import urllib.request
from base64 import b64encode

import boto3
import pycurl
Expand Down Expand Up @@ -860,7 +860,7 @@ def __init__(self, camera_id):

def _request(self, url, method, body=None):
base64string = b64encode(f'{self._username}:{self._password}')
headers = { 'Authorization' : 'Basic %s' % base64string }
headers = {'Authorization': 'Basic %s' % base64string}
if body is not None:
headers.update('Content-Length', '%d' % len(body))
self.debug('request: ' + method + ' ' + url)
Expand All @@ -870,7 +870,9 @@ def _request(self, url, method, body=None):
utils.urlopen(request)
except urllib.HTTPError as e:
if method == 'MKCOL' and e.code == 405:
self.debug('MKCOL failed with code 405, this is normal if the folder exists')
self.debug(
'MKCOL failed with code 405, this is normal if the folder exists'
)
else:
raise e

Expand All @@ -894,7 +896,7 @@ def upload_data(self, filename, mime_type, data, ctime, camera_name):
path = self._location.strip('/') + '/' + os.path.dirname(filename) + '/'
filename = os.path.basename(filename)
self._make_dirs(path)
self.debug('uploading %s of %s bytes' % (filename, len(data)))
self.debug(f'uploading {filename} of {len(data)} bytes')
self._request(self._server + path + filename, 'PUT', bytearray(data))
self.debug('upload done')

Expand All @@ -903,7 +905,7 @@ def dump(self):
'server': self._server,
'username': self._username,
'password': self._password,
'location': self._location
'location': self._location,
}

def load(self, data):
Expand Down

0 comments on commit a72e8b3

Please sign in to comment.