only check resume file if set

This commit is contained in:
j 2017-01-05 01:43:31 +01:00
parent 9e40462d78
commit 69b6e08731

View file

@ -1078,7 +1078,7 @@ class API(ox.API):
def upload_chunks(self, url, filename, data=None): def upload_chunks(self, url, filename, data=None):
form = ox.MultiPartForm() form = ox.MultiPartForm()
resume = None resume = None
if os.path.exists(self._resume_file): if self._resume_file and os.path.exists(self._resume_file):
with open(self._resume_file) as f: with open(self._resume_file) as f:
try: try:
resume = json.load(f) resume = json.load(f)
@ -1165,15 +1165,16 @@ class API(ox.API):
print('server offset out of sync, continue from', data['offset']) print('server offset out of sync, continue from', data['offset'])
done = data['offset'] done = data['offset']
f.seek(done) f.seek(done)
with open(self._resume_file, 'w') as r: if self._resume_file:
json.dump({ with open(self._resume_file, 'w') as r:
'uploadUrl': uploadUrl, json.dump({
'chunkUploadUrl': url, 'uploadUrl': uploadUrl,
'url': result_url, 'chunkUploadUrl': url,
'offset': done 'url': result_url,
}, r, indent=2) 'offset': done
}, r, indent=2)
chunk = f.read(CHUNK_SIZE) chunk = f.read(CHUNK_SIZE)
if os.path.exists(self._resume_file): if self._resume_file and os.path.exists(self._resume_file):
os.unlink(self._resume_file) os.unlink(self._resume_file)
resume = None resume = None
if result_url: if result_url: