如何使用aws s3 sdk复制多个文件

huangapple go评论96阅读模式
英文:

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);

我该如何提供多个文件路径?

例如:源文件

  1. A/srcFolderName/123/file.txt
  2. A/srcFolderName/456/file.txt
  3. A/srcFolderName/789/file.txt
  4. A/srcFolderName/112/file.txt
  5. A/srcFolderName/101/file.txt

需要复制的文件是 1、2 和 5。

复制后:

  1. A/targetFolderName/123/file.txt
  2. A/targetFolderName/456/file.txt
  3. 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

  1. A/srcFolderName/123/file.txt
  2. A/srcFolderName/456/file.txt
  3. A/srcFolderName/789/file.txt
  4. A/srcFolderName/112/file.txt
  5. A/srcFolderName/101/file.txt

Files need to copy are 1,2,5.

After copy

  1. A/targetFolderName/123/file.txt
  2. A/targetFolderName/456/file.txt
  3. 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.

huangapple
  • 本文由 发表于 2020年9月6日 17:18:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/63762556.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定