Complete a multipart_upload with boto3?

前端 未结 6 2280
-上瘾入骨i
-上瘾入骨i 2020-12-28 21:31

Tried this:

import boto3
from boto3.s3.transfer import TransferConfig, S3Transfer
path = \"/temp/\"
fileName = \"bigFile.gz\" # this happens to be a 5.9 Gig         


        
6条回答
  •  暖寄归人
    2020-12-28 21:45

    Change Part to Part1

    import boto3
    
    bucket = 'bucket'
    path = "/temp/"
    fileName = "bigFile.gz"
    key = 'key'
    
    s3 = boto3.client('s3')
    
    # Initiate the multipart upload and send the part(s)
    mpu = s3.create_multipart_upload(Bucket=bucket, Key=key)
    with open(path+fileName,'rb') as data:
        part1 = s3.upload_part(Bucket=bucket
                           , Key=key
                           , PartNumber=1
                           , UploadId=mpu['UploadId']
                           , Body=data)
    
    # 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': part1['ETag']
        }
       ]
      }
    
    # Now the upload works!
    s3.complete_multipart_upload(Bucket=bucket
                             , Key=key
                             , UploadId=mpu['UploadId']
                             , MultipartUpload=part_info)
    

提交回复
热议问题