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.

Retrieves objects from Amazon S3.

Note:

For PCL and Unity this operation is only available in asynchronous form. Please refer to GetObjectAsync.

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

Syntax

C#
public abstract GetObjectResponse GetObject(
         GetObjectRequest request
)
Parameters
request
Type: Amazon.S3.Model.GetObjectRequest

Container for the necessary parameters to execute the GetObject service method.

Return Value
The response from the GetObject service method, as returned by S3.

Examples

This example shows how to get an object.

GetObject sample


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

// Create a GetObject request
GetObjectRequest request = new GetObjectRequest
{
    BucketName = "SampleBucket",
    Key = "Item1"
};

// Issue request and remember to dispose of the response
using (GetObjectResponse response = client.GetObject(request))
{
    using (StreamReader reader = new StreamReader(response.ResponseStream))
    {
        string contents = reader.ReadToEnd();
        Console.WriteLine("Object - " + response.Key);
        Console.WriteLine(" Version Id - " + response.VersionId);
        Console.WriteLine(" Contents - " + contents);
    }
}

                

This example shows how to get an object and write it to a local file.

GetObject WriteResponseStreamToFile Sample


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

// Create a GetObject request
GetObjectRequest request = new GetObjectRequest
{
    BucketName = "SampleBucket",
    Key = "Item1"
};

// Issue request and remember to dispose of the response
using (GetObjectResponse response = client.GetObject(request))
{
    // Save object to local file
    response.WriteResponseStreamToFile("Item1.txt");
}

                

Version Information

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

Portable Class Library:
Supported in: Windows Store Apps
Supported in: Windows Phone 8.1
Supported in: Xamarin Android
Supported in: Xamarin iOS (Unified)
Supported in: Xamarin.Forms

Unity:
Supported Versions: 4.6 and above
Supported Platforms: Android, iOS, Standalone