

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 從 Snowball Edge 上 Snowball Edge 上 Amazon S3 相容儲存中的儲存貯體取得物件
<a name="objects-get-s3-snow"></a>

下列範例使用 從 Snowball Edge 儲存貯體上的 Amazon S3 相容儲存體取得名為 {{sample-object.xml}} 的物件 AWS CLI。SDK 命令為 `s3-snow:GetObject`。若要使用此命令，請以您自己的資訊取代每個 使用者輸入預留位置。

```
aws s3api get-object --bucket {{sample-bucket}} --key {{sample-object.xml}} --endpoint-url {{s3api-endpoint-ip}} --profile {{your-profile}}
```

如需此命令的詳細資訊，請參閱《 *AWS CLI 命令參考*》中的 [get-object](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3api/get-object.html)。

下列 Snowball Edge 上的 Amazon S3 相容儲存體範例會使用適用於 Java 的 SDK 取得物件。若要使用此命令，請以您自己的資訊取代每個 使用者輸入預留位置。如需詳細資訊，請參閱《Amazon Simple Storage Service API 參考》[https://docs.aws.amazon.com/AmazonS3/latest/API/](https://docs.aws.amazon.com/AmazonS3/latest/API/)中的 [GetObject](https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObject.html)。

```
import com.amazonaws.AmazonServiceException;
import com.amazonaws.SdkClientException;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.GetObjectRequest;
import com.amazonaws.services.s3.model.ResponseHeaderOverrides;
import com.amazonaws.services.s3.model.S3Object;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class GetObject {
    public static void main(String[] args) throws IOException {
        String bucketName = "*** Bucket name ***";
        String key = "*** Object key ***";

        S3Object fullObject = null, objectPortion = null, headerOverrideObject = null;
        try {
            // This code expects that you have AWS credentials set up per:
            // https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/setup-credentials.html
            AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                    .enableUseArnRegion()
                    .build();
            GetObjectRequest getObjectRequest = GetObjectRequest.builder()
                    .bucket(bucketName)
                    .key(key)
                    .build());

s3Client.getObject(getObjectRequest);
        } catch (AmazonServiceException e) {
            // The call was transmitted successfully, but Amazon S3 couldn't process
            // it, so it returned an error response.
            e.printStackTrace();
        } catch (SdkClientException e) {
            // Amazon S3 couldn't be contacted for a response, or the client
            // couldn't parse the response from Amazon S3.
            e.printStackTrace();
        } finally {
            // To ensure that the network connection doesn't remain open, close any open input streams.
            if (fullObject != null) {
                fullObject.close();
            }
            if (objectPortion != null) {
                objectPortion.close();
            }
            if (headerOverrideObject != null) {
                headerOverrideObject.close();
            }
        }
    }

    private static void displayTextInputStream(InputStream input) throws IOException {
        // Read the text input stream one line at a time and display each line.
        BufferedReader reader = new BufferedReader(new InputStreamReader(input));
        String line = null;
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
        }
        System.out.println();
    }
}
```