本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
在 Snow Family 设备上列出 Snow Family 设备上兼容 Amazon S3 的存储空间中的存储段中的对象
以下示例使用 AWS CLI列出了 Snow 系列设备存储桶上与 Amazon S3 兼容的存储。SDK命令是s3-snow:ListObjectsV2
。要使用此命令,请将每个用户输入占位符替换为您自己的信息。
aws s3api list-objects-v2 --bucket
sample-bucket
--profileyour-profile
--endpoint-urls3api-endpoint-ip
有关此命令的更多信息,请参阅《AWS CLI 命令参考》中的 list-objects-v2
以下 Snow Family 设备上兼容 Amazon S3 的存储示例使用SDK适用于 Java 的列出了存储桶中的对象。要使用此命令,请将每个用户输入占位符替换为您自己的信息。
此示例使用 ListObjectsV2,这是该 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(); } } }