-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
completing multipart upload #50
Comments
@owenrumney this is really not obvious from the documentation, so it took me a few tries to get right. Multipart uploads require information about each part when you try to complete the upload. This is how you can accomplish it: import boto3
bucket = 'my-bucket'
key = 'mp-test.txt'
s3 = boto3.client('s3')
# Initiate the multipart upload and send the part(s)
mpu = s3.create_multipart_upload(Bucket=bucket, Key=key)
part1 = s3.upload_part(Bucket=bucket, Key=key, PartNumber=1,
UploadId=mpu['UploadId'], Body='Hello, world!')
# Next, we need to gather information about each part to complete
# the upload. Needed are the part number and ETag.
part_info = {
'Parts': [
{
'PartNumber': 1,
'ETag': part['ETag']
}
]
}
# Now the upload works!
s3.complete_multipart_upload(Bucket=bucket, Key=key, UploadId=mpu['UploadId'],
MultipartUpload=part_info) I'll see what can be done about updating the documentation upstream. Let me know if you have any other questions! Also, you can enable low-level logging at any time with this: boto3.set_stream_logger(name='botocore') |
@danielgtaylor thanks, thats much better. I'd seen from the API docs this was the general form but wasn't completely clear. If the documentation could just detail the structure of dict that would probably have been enough. |
What is the ETag? the dict, part, is not defined in this example. |
ETag is part of the response of method s3.upload_part(). See the response structure in the doc: https://boto3.readthedocs.org/en/latest/reference/services/s3.html#S3.Client.upload_part I guess the typo in the example is confusing you.
|
Hi,
Now it is throwing the same error. can any one solve this issue. |
You are overwriting the parts = {
'PartNumber': i,
'ETag': part['ETag']
}
part_info['Parts'].append(parts) Also it might be worth reading in an actual file, instead of using static |
Is the “ MultipartUpload” REQUIRED? rep = s3.complete_multipart_upload(Bucket='bucket',
Key='wentao.mp4',
UploadId='2~in_WUwt5z4g7ri1yfT_MiaRqAs8MRXG') the raised botocore.exceptions.ClientError: An error occurred (MalformedXML) when calling the CompleteMultipartUpload operation: Unknown |
I'm having trouble with completing a multipart upload
given the following test code
I don't know what I'm supposed to be setting MultipartUpload to and can't work it out in the docs. I see it needs to be a dict but not sure what it should contain.
Without it, I get the error
ClientError: An error occurred (InvalidRequest) when calling the CompleteMultipartUpload operation: You must specify at least one part
The text was updated successfully, but these errors were encountered: