AWS SDK Version 4 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.

Downloads the content from Amazon S3 based on the request and returns response metadata. To track the progress of the download, add an event listener to the request's WriteObjectProgressEvent.

Note:

For .NET Core this operation is only available in asynchronous form. Please refer to DownloadWithResponseAsync.

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

Syntax

C#
public virtual TransferUtilityDownloadResponse DownloadWithResponse(
         TransferUtilityDownloadRequest request
)

Parameters

request
Type: Amazon.S3.Transfer.TransferUtilityDownloadRequest

Contains all the parameters required to download an Amazon S3 object.

Return Value


Response metadata including headers and version information from the download.

Remarks

This method uses parallel downloads to significantly improve throughput compared to the standard Amazon.S3.Transfer.ITransferUtility.Download(Amazon.S3.Transfer.TransferUtilityDownloadRequest) method.

How it works:

For large objects, the download is automatically split into parts (default 8MB per part)Multiple parts are downloaded concurrently using parallel requests to S3Downloaded parts are written directly to the file as they arrive

Multipart Download Strategy:

The Amazon.S3.Transfer.BaseDownloadRequest.MultipartDownloadType property controls how parts are downloaded (default: MultipartDownloadType.PART):

PART (default): Uses the original part boundaries from when the object was uploaded with multipart upload. This is more efficient as it aligns with S3's internal part structure, but requires that the object was uploaded using multipart upload. The Amazon.S3.Transfer.BaseDownloadRequest.PartSize property is ignored in this mode.RANGE: Uses range-based downloads with configurable part sizes via the Amazon.S3.Transfer.BaseDownloadRequest.PartSize property. This works with any object (whether uploaded as single-part or multipart) and provides more flexibility in controlling download part sizes.

When to use PART vs RANGE:

Use PART mode (default) when you know the object was uploaded using multipart upload and want optimal performance.Use RANGE mode when the object's upload method is unknown, when you need specific part sizes, or when downloading objects that were uploaded as a single part.

Configuration Options:

You can customize the download behavior using Amazon.S3.Transfer.TransferUtilityConfig:

var config = new TransferUtilityConfig
{
    // Control how many parts download in parallel (default: 10)
    ConcurrentServiceRequests = 20
};
var transferUtility = new TransferUtility(s3Client, config);
                

Use Amazon.S3.Transfer.TransferUtilityConfig.ConcurrentServiceRequests to control parallel download threads.

You can also customize the part size per request using Amazon.S3.Transfer.BaseDownloadRequest.PartSize:

var request = new TransferUtilityDownloadRequest
{
    BucketName = "my-bucket",
    Key = "my-key",
    FilePath = "local-file.txt",
    PartSize = 16 * 1024 * 1024,  // Use 16MB parts instead of default 8MB
    MultipartDownloadType = MultipartDownloadType.RANGE  // Enable RANGE mode to use custom PartSize
};
var response = transferUtility.DownloadWithResponse(request);
                

Additional Performance Settings:

You can also tune the S3 client's Amazon.Runtime.ClientConfig.BufferSize property to control the buffer size used when reading from S3 response streams and writing to the local file. The default buffer size is 8KB. Increasing this value may improve throughput for large downloads at the cost of increased memory usage.

var s3Config = new AmazonS3Config
{
    BufferSize = 64 * 1024  // Use 64KB buffer instead of default 8KB
};
var s3Client = new AmazonS3Client(s3Config);
var transferUtility = new TransferUtility(s3Client);
                

Version Information

.NET:
Supported in: 8.0 and newer, Core 3.1

.NET Standard:
Supported in: 2.0

.NET Framework:
Supported in: 4.7.2 and newer