AWS SDK Version 3 for .NET
API Reference

AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

Container for the parameters to the UploadPart operation. Uploads a part in a multipart upload.

In this operation, you provide new data as a part of an object in your request. However, you have an option to specify your existing Amazon S3 object as a data source for the part you are uploading. To upload a part from an existing object, you use the UploadPartCopy operation.

You must initiate a multipart upload (see CreateMultipartUpload) before you can upload any part. In response to your initiate request, Amazon S3 returns an upload ID, a unique identifier that you must include in your upload part request.

Part numbers can be any number from 1 to 10,000, inclusive. A part number uniquely identifies a part and also defines its position within the object being created. If you upload a new part using the same part number that was used with a previous part, the previously uploaded part is overwritten.

For information about maximum and minimum part sizes and other multipart upload specifications, see Multipart upload limits in the Amazon S3 User Guide.

After you initiate multipart upload and upload one or more parts, you must either complete or abort multipart upload in order to stop getting charged for storage of the uploaded parts. Only after you either complete or abort multipart upload, Amazon S3 frees up the parts storage and stops charging you for the parts storage.

For more information on multipart uploads, go to Multipart Upload Overview in the Amazon S3 User Guide .

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://bucket_name.s3express-az_id.region.amazonaws.com/key-name. Path-style requests are not supported. For more information, see Regional and Zonal endpoints in the Amazon S3 User Guide.

Permissions
  • General purpose bucket permissions - For information on the permissions required to use the multipart upload API, see Multipart Upload and Permissions in the Amazon S3 User Guide.

  • Directory bucket permissions - To grant access to this API operation on a directory bucket, we recommend that you use the CreateSession 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.

Data integrity

General purpose bucket - To ensure that data is not corrupted traversing the network, specify the Content-MD5 header in the upload part request. Amazon S3 checks the part data against the provided MD5 value. If they do not match, Amazon S3 returns an error. If the upload request is signed with Signature Version 4, then Amazon Web Services S3 uses the x-amz-content-sha256 header as a checksum instead of Content-MD5. For more information see Authenticating Requests: Using the Authorization Header (Amazon Web Services Signature Version 4).

Directory buckets - MD5 is not supported by directory buckets. You can use checksum algorithms to check object integrity.

Encryption
  • General purpose bucket - Server-side encryption is for data encryption at rest. Amazon S3 encrypts your data as it writes it to disks in its data centers and decrypts it when you access it. You have mutually exclusive options to protect data using server-side encryption in Amazon S3, depending on how you choose to manage the encryption keys. Specifically, the encryption key options are Amazon S3 managed keys (SSE-S3), Amazon Web Services KMS keys (SSE-KMS), and Customer-Provided Keys (SSE-C). Amazon S3 encrypts data with server-side encryption using Amazon S3 managed keys (SSE-S3) by default. You can optionally tell Amazon S3 to encrypt data at rest using server-side encryption with other key options. The option you use depends on whether you want to use KMS keys (SSE-KMS) or provide your own encryption key (SSE-C).

    Server-side encryption is supported by the S3 Multipart Upload operations. Unless you are using a customer-provided encryption key (SSE-C), you don't need to specify the encryption parameters in each UploadPart request. Instead, you only need to specify the server-side encryption parameters in the initial Initiate Multipart request. For more information, see CreateMultipartUpload.

    If you request server-side encryption using a customer-provided encryption key (SSE-C) in your initiate multipart upload request, you must provide identical encryption information in each part upload using the following request headers.

    • x-amz-server-side-encryption-customer-algorithm

    • x-amz-server-side-encryption-customer-key

    • x-amz-server-side-encryption-customer-key-MD5

  • Directory bucket - For directory buckets, only server-side encryption with Amazon S3 managed keys (SSE-S3) (AES256) is supported.

For more information, see Using Server-Side Encryption in the Amazon S3 User Guide.

Special errors
  • 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

    • SOAP Fault Code Prefix: Client

HTTP Host header syntax

Directory buckets - The HTTP Host header syntax is Bucket_name.s3express-az_id.region.amazonaws.com.

The following operations are related to UploadPart:

Inheritance Hierarchy

System.Object
  Amazon.Runtime.AmazonWebServiceRequest
    Amazon.S3.Model.UploadPartRequest

Namespace: Amazon.S3.Model
Assembly: AWSSDK.S3.dll
Version: 3.x.y.z

Syntax

C#
public class UploadPartRequest : AmazonWebServiceRequest
         IAmazonWebServiceRequest

The UploadPartRequest type exposes the following members

Constructors

NameDescription
Public Method UploadPartRequest()

Properties

NameTypeDescription
Public Property BucketName System.String

Gets and sets the property BucketName.

The name of the bucket to which the multipart upload was initiated.

Directory buckets - When you use this operation with a directory bucket, you must use virtual-hosted-style requests in the format Bucket_name.s3express-az_id.region.amazonaws.com. Path-style requests are not supported. Directory bucket names must be unique in the chosen Availability Zone. Bucket names must follow the format bucket_base_name--az-id--x-s3 (for example, DOC-EXAMPLE-BUCKET--usw2-az1--x-s3). For information about bucket naming restrictions, see Directory bucket naming rules in the Amazon S3 User Guide.

Access points - When you use this action with an access point, you must provide the alias of the access point in place of the bucket name or specify the access point ARN. When using the access point ARN, you must direct requests to the access point hostname. The access point hostname takes the form AccessPointName-AccountId.s3-accesspoint.Region.amazonaws.com. When using this action with an access point through the Amazon Web Services SDKs, you provide the access point ARN in place of the bucket name. For more information about access point ARNs, see Using access points in the Amazon S3 User Guide.

Access points and Object Lambda access points are not supported by directory buckets.

S3 on Outposts - When you use this action with Amazon S3 on Outposts, you must direct requests to the S3 on Outposts hostname. The S3 on Outposts hostname takes the form AccessPointName-AccountId.outpostID.s3-outposts.Region.amazonaws.com. When you use this action with S3 on Outposts through the Amazon Web Services SDKs, you provide the Outposts access point ARN in place of the bucket name. For more information about S3 on Outposts ARNs, see What is S3 on Outposts? in the Amazon S3 User Guide.

Public Property CalculateContentMD5Header System.Boolean

Gets or sets whether the Content-MD5 header should be calculated for upload.

Public Property ChecksumAlgorithm Amazon.S3.ChecksumAlgorithm

Gets and sets the property ChecksumAlgorithm.

Indicates the algorithm used to create the checksum for the object when you use the SDK. This header will not provide any additional functionality if you don't use the SDK. When you send this header, there must be a corresponding x-amz-checksum or x-amz-trailer header sent. Otherwise, Amazon S3 fails the request with the HTTP status code 400 Bad Request. For more information, see Checking object integrity in the Amazon S3 User Guide.

If you provide an individual checksum, Amazon S3 ignores any provided ChecksumAlgorithm parameter.

This checksum algorithm must be the same for all parts and it match the checksum value supplied in the CreateMultipartUpload request.

Public Property ChecksumCRC32 System.String

Gets and sets the property 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 specifies the base64-encoded, 32-bit CRC32 checksum of the object. For more information, see Checking object integrity in the Amazon S3 User Guide.

Public Property ChecksumCRC32C System.String

Gets and sets the property 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 specifies the base64-encoded, 32-bit CRC32C checksum of the object. For more information, see Checking object integrity in the Amazon S3 User Guide.

Public Property ChecksumSHA1 System.String

Gets and sets the property 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 specifies the base64-encoded, 160-bit SHA-1 digest of the object. For more information, see Checking object integrity in the Amazon S3 User Guide.

Public Property ChecksumSHA256 System.String

Gets and sets the property 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 specifies the base64-encoded, 256-bit SHA-256 digest of the object. For more information, see Checking object integrity in the Amazon S3 User Guide.

Public Property DisableDefaultChecksumValidation System.Nullable<System.Boolean>

WARNING: Setting DisableDefaultChecksumValidation to true disables the default data integrity check on upload requests.

When true, checksum verification will not be used in upload requests. This may increase upload performance under high CPU loads. Setting DisableDefaultChecksumValidation sets the deprecated property DisableMD5Stream to the same value. The default value is false. Set this value to true to disable the default checksum validation used in all S3 upload requests or override this value per request by setting the DisableDefaultChecksumValidation property on Amazon.S3.Model.PutObjectRequest, Amazon.S3.Model.UploadPartRequest, or Amazon.S3.Transfer.TransferUtilityUploadRequest.

Checksums, SigV4 payload signing, and HTTPS each provide some data integrity verification. If DisableDefaultChecksumValidation is true and DisablePayloadSigning is true, then the possibility of data corruption is completely dependent on HTTPS being the only remaining source of data integrity verification.

This flag is a rename of the Amazon.S3.Model.UploadPartRequest.DisableMD5Stream property

Public Property DisableMD5Stream System.Nullable<System.Boolean>

WARNING: Setting DisableMD5Stream to true disables the MD5 data integrity check on upload requests.This property has been deprecated in favor of Amazon.S3.Model.UploadPartRequest.DisableDefaultChecksumValidation Setting the value of DisableMD5Stream will set DisableDefaultChecksumValidation to the same value and vice versa. This property was left here for backwards compatibility.

When true, MD5Stream will not be used in upload requests. This may increase upload performance under high CPU loads. The default value is false. Set this value to true to disable MD5Stream use in all S3 upload requests or override this value per request by setting the DisableMD5Stream property on PutObjectRequest, UploadPartRequest, or TransferUtilityUploadRequest.

MD5Stream, SigV4 payload signing, and HTTPS each provide some data integrity verification. If DisableMD5Stream is true and DisablePayloadSigning is true, then the possibility of data corruption is completely dependant on HTTPS being the only remaining source of data integrity verification.

Public Property DisablePayloadSigning System.Nullable<System.Boolean>

WARNING: Setting DisablePayloadSigning to true disables the SigV4 payload signing data integrity check on this request.

If using SigV4, the DisablePayloadSigning flag controls if the payload should be signed on a request by request basis. By default this flag is null which will use the default client behavior. The default client behavior is to sign the payload. When DisablePayloadSigning is true, the request will be signed with an UNSIGNED-PAYLOAD value. Setting DisablePayloadSigning to true requires that the request is sent over a HTTPS connection.

Under certain circumstances, such as uploading to S3 while using MD5 hashing, it may be desireable to use UNSIGNED-PAYLOAD to decrease signing CPU usage. This flag only applies to Amazon S3 PutObject and UploadPart requests.

MD5Stream, SigV4 payload signing, and HTTPS each provide some data integrity verification. If DisableMD5Stream is true and DisablePayloadSigning is true, then the possibility of data corruption is completely dependant on HTTPS being the only remaining source of data integrity verification.

Public Property ExpectedBucketOwner System.String

Gets and sets the property 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).

Public Property FilePath System.String

Full path and name of a file from which the content for the part is retrieved.

For WinRT and Windows Phone this property must be in the form of "ms-appdata:///local/file.txt".

Public Property FilePosition System.Int64

Position in the file specified by FilePath from which to retrieve the content of the part. This field is required when a file path is specified. It is ignored when using the InputStream property.

Public Property InputStream System.IO.Stream

Input stream for the request; content for the request will be read from the stream.

Public Property IsLastPart System.Boolean

Caller needs to set this to true when uploading the last part. This property only needs to be set when using the AmazonS3EncryptionClient.

Public Property Key System.String

The key of the object.

Public Property MD5Digest System.String

An MD5 digest for the part.

Public Property PartNumber System.Int32

Gets and sets the property PartNumber.

Part number of part being uploaded. This is a positive integer between 1 and 10,000.

Public Property PartSize System.Int64

The size of the part to be uploaded.

Public Property ReadWriteTimeout System.Nullable<System.TimeSpan>

Overrides the default ReadWriteTimeout value.

Public Property RequestPayer Amazon.S3.RequestPayer

Confirms that the requester knows that she or he will be charged for the request. Bucket owners need not specify this parameter in their requests.

Public Property ServerSideEncryptionCustomerMethod Amazon.S3.ServerSideEncryptionCustomerMethod

The Server-side encryption algorithm to be used with the customer provided key.

Specifies the algorithm to use to when encrypting the object (for example, AES256).

This functionality is not supported for directory buckets.

Public Property ServerSideEncryptionCustomerProvidedKey System.String

The base64-encoded encryption key for Amazon S3 to use to encrypt the object

Using the encryption key you provide as part of your request Amazon S3 manages both the encryption, as it writes to disks, and decryption, when you access your objects. Therefore, you don't need to maintain any data encryption code. The only thing you do is manage the encryption keys you provide.

When you retrieve an object, you must provide the same encryption key as part of your request. Amazon S3 first verifies the encryption key you provided matches, and then decrypts the object before returning the object data to you.

Important: Amazon S3 does not store the encryption key you provide.

This functionality is not supported for directory buckets.

Public Property ServerSideEncryptionCustomerProvidedKeyMD5 System.String

The MD5 of the customer encryption key specified in the ServerSideEncryptionCustomerProvidedKey property. The MD5 is base 64 encoded. This field is optional, the SDK will calculate the MD5 if this is not set.

This functionality is not supported for directory buckets.

Public Property StreamTransferProgress System.EventHandler<Amazon.Runtime.StreamTransferProgressArgs>

Attach a callback that will be called as data is being sent to the AWS Service.

Public Property Timeout System.Nullable<System.TimeSpan>

Overrides the default request timeout value.

Public Property UploadId System.String

Upload ID identifying the multipart upload whose part is being uploaded.

Public Property UseChunkEncoding System.Boolean

If this value is set to true then a chunked encoding upload will be used for the request. Default: true.

Examples

This example shows how to upload 13MB of data using mutlipart upload.
The data is contained in a stream and the upload is done in 3 parts: 5MB, 5MB, then the remainder.

Multipart Upload Sample


int MB = (int)Math.Pow(2, 20);

// Create a client
AmazonS3Client client = new AmazonS3Client();

// Define input stream
Stream inputStream = Create13MBDataStream();

// Initiate multipart upload
InitiateMultipartUploadRequest initRequest = new InitiateMultipartUploadRequest
{
    BucketName = "SampleBucket",
    Key = "Item1"
};
InitiateMultipartUploadResponse initResponse = client.InitiateMultipartUpload(initRequest);

// Upload part 1
UploadPartRequest uploadRequest = new UploadPartRequest
{
    BucketName = "SampleBucket",
    Key = "Item1",
    UploadId = initResponse.UploadId,
    PartNumber = 1,
    PartSize = 5 * MB,
    InputStream = inputStream
};
UploadPartResponse up1Response = client.UploadPart(uploadRequest);

// Upload part 2
uploadRequest = new UploadPartRequest
{
    BucketName = "SampleBucket",
    Key = "Item1",
    UploadId = initResponse.UploadId,
    PartNumber = 2,
    PartSize = 5 * MB,
    InputStream = inputStream
};
UploadPartResponse up2Response = client.UploadPart(uploadRequest);

// Upload part 3
uploadRequest = new UploadPartRequest
{
    BucketName = "SampleBucket",
    Key = "Item1",
    UploadId = initResponse.UploadId,
    PartNumber = 3,
    InputStream = inputStream
};
UploadPartResponse up3Response = client.UploadPart(uploadRequest);

// List parts for current upload
ListPartsRequest listPartRequest = new ListPartsRequest
{
    BucketName = "SampleBucket",
    Key = "Item1",
    UploadId = initResponse.UploadId
};
ListPartsResponse listPartResponse = client.ListParts(listPartRequest);
Debug.Assert(listPartResponse.Parts.Count == 3);

// Complete the multipart upload
CompleteMultipartUploadRequest compRequest = new CompleteMultipartUploadRequest
{
    BucketName = "SampleBucket",
    Key = "Item1",
    UploadId = initResponse.UploadId,
    PartETags = new List<PartETag>
    {
        new PartETag { ETag = up1Response.ETag, PartNumber = 1 },
        new PartETag { ETag = up2Response.ETag, PartNumber = 2 },
        new PartETag { ETag = up3Response.ETag, PartNumber = 3 }
    }
};
CompleteMultipartUploadResponse compResponse = client.CompleteMultipartUpload(compRequest);

                

Version Information

.NET Core App:
Supported in: 3.1

.NET Standard:
Supported in: 2.0

.NET Framework:
Supported in: 4.5, 4.0, 3.5