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,6 +1165,7 @@ 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)
if self._resume_file:
with open(self._resume_file, 'w') as r: with open(self._resume_file, 'w') as r:
json.dump({ json.dump({
'uploadUrl': uploadUrl, 'uploadUrl': uploadUrl,
@ -1173,7 +1174,7 @@ class API(ox.API):
'offset': done 'offset': done
}, r, indent=2) }, 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: