C# |
public GetObjectResponse GetObject( GetObjectRequest request )
- request (GetObjectRequest)
- The GetObjectRequest that defines the parameters of the operation.
You must have READ access to the object.
If READ access is granted to an anonymous user, an object can be retrieved without an authorization header. Providing a version-id for the object will fetch the specific version from S3 instead of the most recent one.
You should wrap the response you get from calling GetObject in a using clause.
This ensures that all underlying IO resources allocated for the response
are disposed once the response has been processed. This is one way to
call GetObject:
using (GetObjectResponse response = s3Client.GetObject(request))
{
... Process the response:
Get the Stream, get the content-length, write contents to disk, etc
}
This example shows how to get an object.
// 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); } }
Exception | Condition |
---|---|
ArgumentNullException | |
WebException | |
AmazonS3Exception |