Created
October 28, 2016 23:42
-
-
Save Stonelinks/f69253aee8b4c8772dbdadf641122629 to your computer and use it in GitHub Desktop.
multipart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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