GetObject is the basic operation for retrieving an object stored in Amazon S3.
For more options, use the GetObjectExtended operation.
Example
This example gets the "Nelson" object from the "quotes" bucket.
Sample Request
<GetObject xmlns="http://doc.s3.amazonaws.com/2006-03-01"> <Bucket>quotes</Bucket> <Key>Nelson</Key> <GetMetadata>true</GetMetadata> <GetData>true</GetData> <InlineData>true</InlineData> <AWSAccessKeyId>1D9FVRAYCP1VJEXAMPLE=</AWSAccessKeyId> <Timestamp>2006-03-01T12:00:00.183Z</Timestamp> <Signature>Iuyz3d3P0aTou39dzbqaEXAMPLE=</Signature> </GetObject>
Sample Response
<GetObjectResponse xmlns="http://s3.amazonaws.com/doc/2006-03-01">
<GetObjectResponse>
<Status>
<Code>200</Code>
<Description>OK</Description>
</Status>
<Metadata>
<Name>Content-Type</Name>
<Value>text/plain</Value>
</Metadata>
<Metadata>
<Name>family</Name>
<Value>Muntz</Value>
</Metadata>
<Data>aGEtaGE=</Data>
<LastModified>2006-01-01T12:00:00.000Z</LastModified>
<ETag>"828ef3fdfa96f00ad9f27c383fc9ac7f"</ETag>
</GetObjectResponse>
</GetObjectResponse>Bucket: The bucket from which to retrieve the object.Key: The key that identifies the object.GetMetadata: The metadata is returned with the object if this is true.GetData: The object data is returned if this is true.InlineData: If this is true, then the data is returned, base 64-encoded, as part of the SOAP body of the response. If false, then the data is returned as a SOAP attachment.
The InlineData option is not suitable for use with large
objects. The system limits this operation to working with 1MB of
data or less. A GetObject request with the InlineData flag set
will fail with the InlineDataTooLargeError
status code if the resulting Data parameter would have encoded more
than 1MB. To download large objects, consider calling GetObject
without setting the InlineData flag, or use the REST API
instead.
Metadata: The name-value paired metadata stored with the object.Data: If InlineData was true in the request, this contains the base 64 encoded object data.LastModified: The time that the object was stored in Amazon S3.ETag: The object's entity tag. This is a hash of the object that can be used to do conditional gets.You can read an object only if you have been granted READ access to the object.
To provide GET flexibility, Amazon S3 supports chunked and resumable downloads.
Select from the following:
For large object downloads, you might want to break them into smaller chunks. For more information, see Range GETs
For GET operations that fail, you can design your application
to download the remainder instead of the entire file. For more information, see
REST GET Error Recovery
For some clients, you might want to break large downloads into smaller downloads. To break a GET into smaller units, use Range.
Before you can break a GET into smaller units, you must determine its size. For example, the following request gets the size of the bigfile object.
<ListBucket xmlns="http://doc.s3.amazonaws.com/2006-03-01"> <Bucket>bigbucket</Bucket> <Prefix>bigfile</Prefix> <MaxKeys>1</MaxKeys> <AWSAccessKeyId>1D9FVRAYCP1VJEXAMPLE=</AWSAccessKeyId> <Timestamp>2006-03-01T12:00:00.183Z</Timestamp> <Signature>Iuyz3d3P0aTou39dzbqaEXAMPLE=</Signature> </ListBucket>
Amazon S3 returns the following response.
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01">
<Name>quotes</Name>
<Prefix>N</Prefix>
<MaxKeys>1</MaxKeys>
<IsTruncated>false</IsTruncated>
<Contents>
<Key>bigfile</Key>
<LastModified>2006-01-01T12:00:00.000Z</LastModified>
<ETag>"828ef3fdfa96f00ad9f27c383fc9ac7f"</ETag>
<Size>2023276</Size>
<StorageClass>STANDARD</StorageClass>
<Owner>
<ID>bcaf1ffd86f41caff1a493dc2ad8c2c281e37522a640e161ca5fb16fd081034f</ID>
<DisplayName>bigfile</DisplayName>
</Owner>
</Contents>
</ListBucketResult>
Following is a request that downloads the first megabyte from the bigfile object.
<GetObject xmlns="http://doc.s3.amazonaws.com/2006-03-01"> <Bucket>bigbucket</Bucket> <Key>bigfile</Key> <GetMetadata>true</GetMetadata> <GetData>true</GetData> <InlineData>true</InlineData> <ByteRangeStart>0</ByteRangeStart> <ByteRangeEnd>1048576</ByteRangeEnd> <AWSAccessKeyId>1D9FVRAYCP1VJEXAMPLE=</AWSAccessKeyId> <Timestamp>2006-03-01T12:00:00.183Z</Timestamp> <Signature>Iuyz3d3P0aTou39dzbqaEXAMPLE=</Signature> </GetObject>
Amazon S3 returns the first megabyte of the file and the Etag of the file.
<GetObjectResponse xmlns="http://s3.amazonaws.com/doc/2006-03-01">
<GetObjectResponse>
<Status>
<Code>200</Code>
<Description>OK</Description>
</Status>
<Metadata>
<Name>Content-Type</Name>
<Value>text/plain</Value>
</Metadata>
<Metadata>
<Name>family</Name>
<Value>Muntz</Value>
</Metadata>
<Data>--first megabyte of bigfile--</Data>
<LastModified>2006-01-01T12:00:00.000Z</LastModified>
<ETag>"828ef3fdfa96f00ad9f27c383fc9ac7f"</ETag>
</GetObjectResponse>
</GetObjectResponse>
To ensure the file did not change since the previous portion was downloaded, specify the IfMatch element. Although the IfMatch element is not required, it is recommended for content that is likely to change.
The following is a request that gets the remainder of the file, using the IfMatch request header.
<GetObject xmlns="http://doc.s3.amazonaws.com/2006-03-01"> <Bucket>bigbucket</Bucket> <Key>bigfile</Key> <GetMetadata>true</GetMetadata> <GetData>true</GetData> <InlineData>true</InlineData> <ByteRangeStart>10485761</ByteRangeStart> <ByteRangeEnd>2023276</ByteRangeEnd> <IfMatch>"828ef3fdfa96f00ad9f27c383fc9ac7f"</IfMatch> <AWSAccessKeyId>1D9FVRAYCP1VJEXAMPLE=</AWSAccessKeyId> <Timestamp>2006-03-01T12:00:00.183Z</Timestamp> <Signature>Iuyz3d3P0aTou39dzbqaEXAMPLE=</Signature> </GetObject>
Amazon S3 returns the following response and the remainder of the file.
<GetObjectResponse xmlns="http://s3.amazonaws.com/doc/2006-03-01">
<GetObjectResponse>
<Status>
<Code>200</Code>
<Description>OK</Description>
</Status>
<Metadata>
<Name>Content-Type</Name>
<Value>text/plain</Value>
</Metadata>
<Metadata>
<Name>family</Name>
<Value>>Muntz</Value>
</Metadata>
<Data>--remainder of bigfile--</Data>
<LastModified>2006-01-01T12:00:00.000Z</LastModified>
<ETag>"828ef3fdfa96f00ad9f27c383fc9ac7f"</ETag>
</GetObjectResponse>
</GetObjectResponse>
If an object GET fails, you can get the rest of the file by specifying the range to download.
To do so, you must get the size of the object using ListBucket and perform a
range GET on the remainder of the file. For more information, see
GetObjectExtended.