

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

# 在 Snowball Edge 上列出 Snowball Edge 上 Amazon S3 相容儲存貯體中的物件
<a name="objects-list-s3-snow"></a>

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

```
aws s3api list-objects-v2 --bucket {{sample-bucket}} --endpoint-url {{s3api-endpoint-ip}} --profile {{your-profile}}
```

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

下列 Snowball Edge 上的 Amazon S3 相容儲存體範例使用適用於 Java 的 SDK 列出儲存貯體中的物件。若要使用此命令，請以您自己的資訊取代每個 使用者輸入預留位置。

此範例使用 [ListObjectsV2](https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html)，這是 ListObjects API 操作的最新版本。建議您使用此修訂版本後的 API 操作進行應用程式進行開發。為了回溯相容性，Amazon S3 會繼續支援此 API 操作的舊版本。

```
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.ListObjectsV2Request;
import com.amazonaws.services.s3.model.ListObjectsV2Result;
import com.amazonaws.services.s3.model.S3ObjectSummary;

public class ListObjectsV2 {

    public static void main(String[] args) {
        String bucketName = "*** Bucket name ***";

        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();

            System.out.println("Listing objects");

            // maxKeys is set to 2 to demonstrate the use of
            // ListObjectsV2Result.getNextContinuationToken()
            ListObjectsV2Request req = new ListObjectsV2Request().withBucketName(bucketName).withMaxKeys(2);
            ListObjectsV2Result result;

            do {
                result = s3Client.listObjectsV2(req);

                for (S3ObjectSummary objectSummary : result.getObjectSummaries()) {
                    System.out.printf(" - %s (size: %d)\n", objectSummary.getKey(), objectSummary.getSize());
                }
                // If there are more than maxKeys keys in the bucket, get a continuation token
                // and list the next objects.
                String token = result.getNextContinuationToken();
                System.out.println("Next Continuation Token: " + token);
                req.setContinuationToken(token);
            } while (result.isTruncated());
        } 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();
        }
    }
}
```