將物件複製到 Snow Family 裝置上的 Amazon S3 相容儲存體 - AWS Snowball Edge 開發人員指南

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

將物件複製到 Snow Family 裝置上的 Amazon S3 相容儲存體

下列範例會上傳名為 的檔案 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 for 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(); } } }