AWS S3 copy object source key and destination key

ⅰ亾dé卋堺 提交于 2019-12-13 16:10:02

问题


I am writing JAVA code to copy object within AWS S3.

CopyObjectRequest copyObjRequest = new CopyObjectRequest(srcbucket, srcKey, destbucket, destKey);              
s3Client.copyObject(copyObjRequest);

What is source key and destination key? I read a lot in theory but no where it is mentioned that from where we can get these keys. Maybe I missed some part.

Please help me to get source and destination keys of bucket.... Please provide an example for that also...


回答1:


From the documentation:

CopyObjectRequest(java.lang.String sourceBucketName, java.lang.String sourceKey, java.lang.String destinationBucketName, java.lang.String destinationKey)
Constructs with basic options.

The "sourceKey" and "destinationKey" are the keys of the S3 Objects you are looking to copy. The "sourceKey" is the key of the existing object, and the "destinationKey" is the keyName you want to use for the copy of the source object.

To make a copy of the object in the same bucket:

CopyObjectRequest copyObjRequest = new CopyObjectRequest("myBucket", "myObject.txt", "myBucket", "myNewObject.txt");              
s3Client.copyObject(copyObjRequest);

To make a copy of the object in a different bucket:

CopyObjectRequest copyObjRequest = new CopyObjectRequest("myBucket", "myObject.txt", "myOtherBucket", "myNewObject.txt");              
s3Client.copyObject(copyObjRequest);

Further Reading:

  • S3 Documentation - Object Keys and Metadata
  • S3 Documentation - Working with Amazon S3 Objects


来源:https://stackoverflow.com/questions/33782740/aws-s3-copy-object-source-key-and-destination-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!