英文:
How to copy multiple files using aws s3 sdk
问题
我想使用 AWS S3 SDK for Java 将多个文件从一个文件夹复制到另一个文件夹。我可以看到提供的 copyObject() 方法是针对单个文件的。
以下是文档中提供的代码示例:
CopyObjectRequest copyObjectRequest = new CopyObjectRequest(getBucketName(),
"srcFolderName" + "/" + key, getBucketName(), "targetFolderName" + "/" + key);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentDisposition("attachment");
copyObjectRequest.setNewObjectMetadata(metadata);
getS3Client().copyObject(copyObjectRequest);
我该如何提供多个文件路径?
例如:源文件
- A/srcFolderName/123/file.txt
- A/srcFolderName/456/file.txt
- A/srcFolderName/789/file.txt
- A/srcFolderName/112/file.txt
- A/srcFolderName/101/file.txt
需要复制的文件是 1、2 和 5。
复制后:
- A/targetFolderName/123/file.txt
- A/targetFolderName/456/file.txt
- A/targetFolderName/101/file.txt
英文:
I want to copy multiple files from one folder to another folder using aws s3 sdk java. I can see the method copyObject() provided is for single file.
Below is the code which is provided in documentation.
CopyObjectRequest copyObjectRequest = new CopyObjectRequest(getBucketName(),
"srcFolderName" + "/" + key, getBucketName(), "targetFolderName" + "/" + key);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentDisposition("attachment");
copyObjectRequest.setNewObjectMetadata(metadata);
getS3Client().copyObject(copyObjectRequest);
How can I give multiple files path?
Ex: Source
- A/srcFolderName/123/file.txt
- A/srcFolderName/456/file.txt
- A/srcFolderName/789/file.txt
- A/srcFolderName/112/file.txt
- A/srcFolderName/101/file.txt
Files need to copy are 1,2,5.
After copy
- A/targetFolderName/123/file.txt
- A/targetFolderName/456/file.txt
- A/targetFolderName/101/file.txt
答案1
得分: 2
你不能通过一个 API 调用复制多个对象。
CopyObject
API 调用只会复制一个对象。
然而,你可以通过多个线程发起多个 API 调用,以便并行执行操作。
英文:
You cannot copy multiple objects with one API call.
The CopyObject
API call will only copy one object.
You can, however, issue multiple API calls through multiple threads so that operations are done in parallel.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论