:doc:`MultipartUpload <index>` / Action / complete

********
complete
********



.. py:method:: S3.MultipartUpload.complete(**kwargs)

  

  Completes a multipart upload by assembling previously uploaded parts.

   

  You first initiate the multipart upload and then upload all parts using the `UploadPart <https://docs.aws.amazon.com/AmazonS3/latest/API/API_UploadPart.html>`__ operation or the `UploadPartCopy <https://docs.aws.amazon.com/AmazonS3/latest/API/API_UploadPartCopy.html>`__ operation. After successfully uploading all relevant parts of an upload, you call this ``CompleteMultipartUpload`` operation to complete the upload. Upon receiving this request, Amazon S3 concatenates all the parts in ascending order by part number to create a new object. In the CompleteMultipartUpload request, you must provide the parts list and ensure that the parts list is complete. The CompleteMultipartUpload API operation concatenates the parts that you provide in the list. For each part in the list, you must provide the ``PartNumber`` value and the ``ETag`` value that are returned after that part was uploaded.

   

  The processing of a CompleteMultipartUpload request could take several minutes to finalize. After Amazon S3 begins processing the request, it sends an HTTP response header that specifies a ``200 OK`` response. While processing is in progress, Amazon S3 periodically sends white space characters to keep the connection from timing out. A request could fail after the initial ``200 OK`` response has been sent. This means that a ``200 OK`` response can contain either a success or an error. The error response might be embedded in the ``200 OK`` response. If you call this API operation directly, make sure to design your application to parse the contents of the response and handle it appropriately. If you use Amazon Web Services SDKs, SDKs handle this condition. The SDKs detect the embedded error and apply error handling per your configuration settings (including automatically retrying the request as appropriate). If the condition persists, the SDKs throw an exception (or, for the SDKs that don't use exceptions, they return an error).

   

  Note that if ``CompleteMultipartUpload`` fails, applications should be prepared to retry any failed requests (including 500 error responses). For more information, see `Amazon S3 Error Best Practices <https://docs.aws.amazon.com/AmazonS3/latest/dev/ErrorBestPractices.html>`__.

   

  .. warning::

     

    You can't use ``Content-Type: application/x-www-form-urlencoded`` for the CompleteMultipartUpload requests. Also, if you don't provide a ``Content-Type`` header, ``CompleteMultipartUpload`` can still return a ``200 OK`` response.

     

   

  For more information about multipart uploads, see `Uploading Objects Using Multipart Upload <https://docs.aws.amazon.com/AmazonS3/latest/dev/uploadobjusingmpu.html>`__ in the *Amazon S3 User Guide*.

   

  .. note::

    

    **Directory buckets** - For directory buckets, you must make requests for this API operation to the Zonal endpoint. These endpoints support virtual-hosted-style requests in the format ``https://amzn-s3-demo-bucket.s3express-zone-id.region-code.amazonaws.com/key-name ``. Path-style requests are not supported. For more information about endpoints in Availability Zones, see `Regional and Zonal endpoints for directory buckets in Availability Zones <https://docs.aws.amazon.com/AmazonS3/latest/userguide/endpoint-directory-buckets-AZ.html>`__ in the *Amazon S3 User Guide*. For more information about endpoints in Local Zones, see `Concepts for directory buckets in Local Zones <https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-lzs-for-directory-buckets.html>`__ in the *Amazon S3 User Guide*.

    

    Permissions  

  
  * **General purpose bucket permissions** - For information about permissions required to use the multipart upload API, see `Multipart Upload and Permissions <https://docs.aws.amazon.com/AmazonS3/latest/dev/mpuAndPermissions.html>`__ in the *Amazon S3 User Guide*. If you provide an `additional checksum value <https://docs.aws.amazon.com/AmazonS3/latest/API/API_Checksum.html>`__ in your ``MultipartUpload`` requests and the object is encrypted with Key Management Service, you must have permission to use the ``kms:Decrypt`` action for the ``CompleteMultipartUpload`` request to succeed.
   
  * **Directory bucket permissions** - To grant access to this API operation on a directory bucket, we recommend that you use the `CreateSession <https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateSession.html>`__ API operation for session-based authorization. Specifically, you grant the ``s3express:CreateSession`` permission to the directory bucket in a bucket policy or an IAM identity-based policy. Then, you make the ``CreateSession`` API call on the bucket to obtain a session token. With the session token in your request header, you can make API requests to this operation. After the session token expires, you make another ``CreateSession`` API call to generate a new session token for use. Amazon Web Services CLI or SDKs create session and refresh the session token automatically to avoid service interruptions when a session expires. For more information about authorization, see `CreateSession <https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateSession.html>`__. If the object is encrypted with SSE-KMS, you must also have the ``kms:GenerateDataKey`` and ``kms:Decrypt`` permissions in IAM identity-based policies and KMS key policies for the KMS key.
  

    Special errors  

  
  * Error Code: ``EntityTooSmall`` 

    
    * Description: Your proposed upload is smaller than the minimum allowed object size. Each part must be at least 5 MB in size, except the last part.
     
    * HTTP Status Code: 400 Bad Request
    

  
   
  * Error Code: ``InvalidPart`` 

    
    * Description: One or more of the specified parts could not be found. The part might not have been uploaded, or the specified ETag might not have matched the uploaded part's ETag.
     
    * HTTP Status Code: 400 Bad Request
    

  
   
  * Error Code: ``InvalidPartOrder`` 

    
    * Description: The list of parts was not in ascending order. The parts list must be specified in order by part number.
     
    * HTTP Status Code: 400 Bad Request
    

  
   
  * Error Code: ``NoSuchUpload`` 

    
    * Description: The specified multipart upload does not exist. The upload ID might be invalid, or the multipart upload might have been aborted or completed.
     
    * HTTP Status Code: 404 Not Found
    

  
  

    HTTP Host header syntax  

  **Directory buckets** - The HTTP Host header syntax is ``Bucket-name.s3express-zone-id.region-code.amazonaws.com``.

     

  The following operations are related to ``CompleteMultipartUpload``:

   

  
  * `CreateMultipartUpload <https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateMultipartUpload.html>`__
   
  * `UploadPart <https://docs.aws.amazon.com/AmazonS3/latest/API/API_UploadPart.html>`__
   
  * `AbortMultipartUpload <https://docs.aws.amazon.com/AmazonS3/latest/API/API_AbortMultipartUpload.html>`__
   
  * `ListParts <https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListParts.html>`__
   
  * `ListMultipartUploads <https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListMultipartUploads.html>`__
  

   

  .. warning::

     

    You must URL encode any signed header values that contain spaces. For example, if your header value is ``my file.txt``, containing two spaces after ``my``, you must URL encode this value to ``my%20%20file.txt``.

    

  

  See also: `AWS API Documentation <https://docs.aws.amazon.com/goto/WebAPI/s3-2006-03-01/CompleteMultipartUpload>`_  


  **Request Syntax**
  ::

    object = multipart_upload.complete(
        MultipartUpload={
            'Parts': [
                {
                    'ETag': 'string',
                    'ChecksumCRC32': 'string',
                    'ChecksumCRC32C': 'string',
                    'ChecksumCRC64NVME': 'string',
                    'ChecksumSHA1': 'string',
                    'ChecksumSHA256': 'string',
                    'PartNumber': 123
                },
            ]
        },
        ChecksumCRC32='string',
        ChecksumCRC32C='string',
        ChecksumCRC64NVME='string',
        ChecksumSHA1='string',
        ChecksumSHA256='string',
        ChecksumType='COMPOSITE'|'FULL_OBJECT',
        MpuObjectSize=123,
        RequestPayer='requester',
        ExpectedBucketOwner='string',
        IfMatch='string',
        IfNoneMatch='string',
        SSECustomerAlgorithm='string',
        SSECustomerKey='string',
        
    )
    
  :type MultipartUpload: dict
  :param MultipartUpload: 

    The container for the multipart upload request information.

    

  
    - **Parts** *(list) --* 

      Array of CompletedPart data types.

       

      If you do not supply a valid ``Part`` with your request, the service sends back an HTTP 400 response.

      

    
      - *(dict) --* 

        Details of the parts that were uploaded.

        

      
        - **ETag** *(string) --* 

          Entity tag returned when the part was uploaded.

          

        
        - **ChecksumCRC32** *(string) --* 

          The Base64 encoded, 32-bit ``CRC32`` checksum of the part. This checksum is present if the multipart upload request was created with the ``CRC32`` checksum algorithm. For more information, see `Checking object integrity <https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html>`__ in the *Amazon S3 User Guide*.

          

        
        - **ChecksumCRC32C** *(string) --* 

          The Base64 encoded, 32-bit ``CRC32C`` checksum of the part. This checksum is present if the multipart upload request was created with the ``CRC32C`` checksum algorithm. For more information, see `Checking object integrity <https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html>`__ in the *Amazon S3 User Guide*.

          

        
        - **ChecksumCRC64NVME** *(string) --* 

          The Base64 encoded, 64-bit ``CRC64NVME`` checksum of the part. This checksum is present if the multipart upload request was created with the ``CRC64NVME`` checksum algorithm to the uploaded object). For more information, see `Checking object integrity <https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html>`__ in the *Amazon S3 User Guide*.

          

        
        - **ChecksumSHA1** *(string) --* 

          The Base64 encoded, 160-bit ``SHA1`` checksum of the part. This checksum is present if the multipart upload request was created with the ``SHA1`` checksum algorithm. For more information, see `Checking object integrity <https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html>`__ in the *Amazon S3 User Guide*.

          

        
        - **ChecksumSHA256** *(string) --* 

          The Base64 encoded, 256-bit ``SHA256`` checksum of the part. This checksum is present if the multipart upload request was created with the ``SHA256`` checksum algorithm. For more information, see `Checking object integrity <https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html>`__ in the *Amazon S3 User Guide*.

          

        
        - **PartNumber** *(integer) --* 

          Part number that identifies the part. This is a positive integer between 1 and 10,000.

           

          .. note::

            

            
            * **General purpose buckets** - In ``CompleteMultipartUpload``, when a additional checksum (including ``x-amz-checksum-crc32``, ``x-amz-checksum-crc32c``, ``x-amz-checksum-sha1``, or ``x-amz-checksum-sha256``) is applied to each part, the ``PartNumber`` must start at 1 and the part numbers must be consecutive. Otherwise, Amazon S3 generates an HTTP ``400 Bad Request`` status code and an ``InvalidPartOrder`` error code.
             
            * **Directory buckets** - In ``CompleteMultipartUpload``, the ``PartNumber`` must start at 1 and the part numbers must be consecutive.
            

            

          

        
      
  
  
  :type ChecksumCRC32: string
  :param ChecksumCRC32: 

    This header can be used as a data integrity check to verify that the data received is the same data that was originally sent. This header specifies the Base64 encoded, 32-bit ``CRC32`` checksum of the object. For more information, see `Checking object integrity <https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html>`__ in the *Amazon S3 User Guide*.

    

  
  :type ChecksumCRC32C: string
  :param ChecksumCRC32C: 

    This header can be used as a data integrity check to verify that the data received is the same data that was originally sent. This header specifies the Base64 encoded, 32-bit ``CRC32C`` checksum of the object. For more information, see `Checking object integrity <https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html>`__ in the *Amazon S3 User Guide*.

    

  
  :type ChecksumCRC64NVME: string
  :param ChecksumCRC64NVME: 

    This header can be used as a data integrity check to verify that the data received is the same data that was originally sent. This header specifies the Base64 encoded, 64-bit ``CRC64NVME`` checksum of the object. The ``CRC64NVME`` checksum is always a full object checksum. For more information, see `Checking object integrity in the Amazon S3 User Guide <https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html>`__.

    

  
  :type ChecksumSHA1: string
  :param ChecksumSHA1: 

    This header can be used as a data integrity check to verify that the data received is the same data that was originally sent. This header specifies the Base64 encoded, 160-bit ``SHA1`` digest of the object. For more information, see `Checking object integrity <https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html>`__ in the *Amazon S3 User Guide*.

    

  
  :type ChecksumSHA256: string
  :param ChecksumSHA256: 

    This header can be used as a data integrity check to verify that the data received is the same data that was originally sent. This header specifies the Base64 encoded, 256-bit ``SHA256`` digest of the object. For more information, see `Checking object integrity <https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html>`__ in the *Amazon S3 User Guide*.

    

  
  :type ChecksumType: string
  :param ChecksumType: 

    This header specifies the checksum type of the object, which determines how part-level checksums are combined to create an object-level checksum for multipart objects. You can use this header as a data integrity check to verify that the checksum type that is received is the same checksum that was specified. If the checksum type doesn’t match the checksum type that was specified for the object during the ``CreateMultipartUpload`` request, it’ll result in a ``BadDigest`` error. For more information, see Checking object integrity in the Amazon S3 User Guide.

    

  
  :type MpuObjectSize: integer
  :param MpuObjectSize: 

    The expected total object size of the multipart upload request. If there’s a mismatch between the specified object size value and the actual object size value, it results in an ``HTTP 400 InvalidRequest`` error.

    

  
  :type RequestPayer: string
  :param RequestPayer: 

    Confirms that the requester knows that they will be charged for the request. Bucket owners need not specify this parameter in their requests. If either the source or destination S3 bucket has Requester Pays enabled, the requester will pay for the corresponding charges. For information about downloading objects from Requester Pays buckets, see `Downloading Objects in Requester Pays Buckets <https://docs.aws.amazon.com/AmazonS3/latest/dev/ObjectsinRequesterPaysBuckets.html>`__ in the *Amazon S3 User Guide*.

     

    .. note::

      

      This functionality is not supported for directory buckets.

      

    

  
  :type ExpectedBucketOwner: string
  :param ExpectedBucketOwner: 

    The account ID of the expected bucket owner. If the account ID that you provide does not match the actual owner of the bucket, the request fails with the HTTP status code ``403 Forbidden`` (access denied).

    

  
  :type IfMatch: string
  :param IfMatch: 

    Uploads the object only if the ETag (entity tag) value provided during the WRITE operation matches the ETag of the object in S3. If the ETag values do not match, the operation returns a ``412 Precondition Failed`` error.

     

    If a conflicting operation occurs during the upload S3 returns a ``409 ConditionalRequestConflict`` response. On a 409 failure you should fetch the object's ETag, re-initiate the multipart upload with ``CreateMultipartUpload``, and re-upload each part.

     

    Expects the ETag value as a string.

     

    For more information about conditional requests, see `RFC 7232 <https://tools.ietf.org/html/rfc7232>`__, or `Conditional requests <https://docs.aws.amazon.com/AmazonS3/latest/userguide/conditional-requests.html>`__ in the *Amazon S3 User Guide*.

    

  
  :type IfNoneMatch: string
  :param IfNoneMatch: 

    Uploads the object only if the object key name does not already exist in the bucket specified. Otherwise, Amazon S3 returns a ``412 Precondition Failed`` error.

     

    If a conflicting operation occurs during the upload S3 returns a ``409 ConditionalRequestConflict`` response. On a 409 failure you should re-initiate the multipart upload with ``CreateMultipartUpload`` and re-upload each part.

     

    Expects the '*' (asterisk) character.

     

    For more information about conditional requests, see `RFC 7232 <https://tools.ietf.org/html/rfc7232>`__, or `Conditional requests <https://docs.aws.amazon.com/AmazonS3/latest/userguide/conditional-requests.html>`__ in the *Amazon S3 User Guide*.

    

  
  :type SSECustomerAlgorithm: string
  :param SSECustomerAlgorithm: 

    The server-side encryption (SSE) algorithm used to encrypt the object. This parameter is required only when the object was created using a checksum algorithm or if your bucket policy requires the use of SSE-C. For more information, see `Protecting data using SSE-C keys <https://docs.aws.amazon.com/AmazonS3/latest/userguide/ServerSideEncryptionCustomerKeys.html#ssec-require-condition-key>`__ in the *Amazon S3 User Guide*.

     

    .. note::

      

      This functionality is not supported for directory buckets.

      

    

  
  :type SSECustomerKey: string
  :param SSECustomerKey: 

    The server-side encryption (SSE) customer managed key. This parameter is needed only when the object was created using a checksum algorithm. For more information, see `Protecting data using SSE-C keys <https://docs.aws.amazon.com/AmazonS3/latest/dev/ServerSideEncryptionCustomerKeys.html>`__ in the *Amazon S3 User Guide*.

     

    .. note::

      

      This functionality is not supported for directory buckets.

      

    

  
  :type SSECustomerKeyMD5: string
  :param SSECustomerKeyMD5: 

    The MD5 server-side encryption (SSE) customer managed key. This parameter is needed only when the object was created using a checksum algorithm. For more information, see `Protecting data using SSE-C keys <https://docs.aws.amazon.com/AmazonS3/latest/dev/ServerSideEncryptionCustomerKeys.html>`__ in the *Amazon S3 User Guide*.

     

    .. note::

      

      This functionality is not supported for directory buckets.

      

        Please note that this parameter is automatically populated if it is not provided. Including this parameter is not required



  
  
  :rtype: :py:class:`s3.Object`
  :returns: Object resource
  