Skip to content

Instantly share code, notes, and snippets.

@Stonelinks
Created October 28, 2016 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Stonelinks/f69253aee8b4c8772dbdadf641122629 to your computer and use it in GitHub Desktop.
Save Stonelinks/f69253aee8b4c8772dbdadf641122629 to your computer and use it in GitHub Desktop.
multipart
def upload_file(client, project_id, job_id, filename, path, mimetype):
mpu = client.post('/v1/files?multipart=1', data={
'project_id': project_id,
'job_id': job_id,
'name': filename,
'type': mimetype,
}, files={'1': '1'}).json()
# split each file up
with open(path, 'rb') as f:
contents = f.read(PART_SIZE)
part = 1
while contents:
buff = io.BytesIO(contents)
client.put('/v1/multipartuploads/%s?part=%d' % (mpu['id'], part), data=buff)
contents = f.read(PART_SIZE)
part += 1
client.post('/v1/multipartuploads/' + mpu['id'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment