将对象复制到 Snow Family 设备上与 Amazon S3 兼容的存储空间和 Snow Family 设备上的存储区 - AWS Snowball Edge 开发者指南

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

将对象复制到 Snow Family 设备上与 Amazon S3 兼容的存储空间和 Snow Family 设备上的存储区

以下示例上传一个名为的文件 sample-object.xml 存储到 Snow Family 设备上与 Amazon S3 兼容的存储空间中,您有权使用该存储桶的写入权限 AWS CLI。要使用此命令,请将每个用户输入占位符替换为您自己的信息。

aws s3api put-object --bucket sample-bucket --key sample-object.xml --body sample-object.xml --profile your-profile --endpoint-url s3api-endpoint-ip

以下 Snow Family 设备上兼容 Amazon S3 的存储示例使用适用SDK于 Java 的将对象复制到同一存储桶中的新对象中。要使用此命令,请将每个用户输入占位符替换为您自己的信息。

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.CopyObjectRequest; add : import java.io.IOException; public class CopyObject { public static void main(String[] args) { String bucketName = "*** Bucket name ***"; String sourceKey = "*** Source object key ***"; String destinationKey = "*** Destination object key ***"; 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(); // Copy the object into a new object in the same bucket. CopyObjectRequest copyObjectRequest = new CopyObjectRequest(sourceKey, destinationKey); s3Client.copyObject(copyObjectRequest); CopyObjectRequest copyObjectRequest = CopyObjectRequest.builder() .sourceKey(sourceKey) .destinationKey(destKey) .build(); } 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(); } } }