Project

General

Profile

Bug #22790 ยป resend_part.py

python script to resend a part during a multipart upload - Casey Bodley, 01/24/2018 09:36 PM

 
#!/usr/bin/python

# perform a multipart upload where a single part is uploaded twice
import boto3
import logging
import sys

# filename as first argument
filename = sys.argv[1]

# endpoint and keys from vstart
endpoint='http://127.0.0.1:8000'
access_key='0555b35654ad1656d804'
secret_key='h7GhxuBLTrlhVUyxSPUKUV8r/2EI4ngqJxD7iBdBYLhwluN30JaT3Q=='

s3 = boto3.resource('s3',
endpoint_url=endpoint,
aws_access_key_id=access_key,
aws_secret_access_key=secret_key)

bucket = s3.Bucket('bucket')
bucket.create()

obj = bucket.Object('multipart')
upload = obj.initiate_multipart_upload()

parts = []
part = upload.Part(1)

# upload the same part twice
with open(filename, 'rb') as body:
part.upload(Body=body)
with open(filename, 'rb') as body:
p = part.upload(Body=body)
parts.append({'PartNumber': 1, 'ETag': p['ETag']})

upload.complete(MultipartUpload={'Parts': parts})
    (1-1/1)