0

在一个请求中,我希望能够将多个特定文件从一个存储桶复制到另一个存储桶。我有单个文件的标准代码,我必须对其进行迭代并引发多个请求才能复制多个文件。有没有办法给出我想从一个存储桶复制到另一个存储桶的文件列表,并且只在一个请求中完成?这就是我的代码现在的样子:

for(int x=0; x < test.length; x++){
CopyObjectRequest request = new CopyObjectRequest();
                request.SourceBucket = tempBucket;
                request.SourceKey = imagekeys[x];
                request.DestinationBucket = stagingBucket;
                request.DestinationKey = imageUrl_Large_key;
                request.CannedACL = S3CannedACL.PublicRead;

                    S3Response response = client.CopyObject(request);
                }
4

2 回答 2

0

Due to how the buckets work, I'm pretty sure there is no way to do a mass copy as part of a single request.

于 2013-10-22T23:20:29.950 回答
0

我认为您可以使用 S3DirectoryInfo 类和 CopyTo 方法在存储桶之间复制文件夹键。但它会为每个文件执行一个请求以移动到目标存储桶,尽管它是一种更优雅的方式。例如,我使用 AWSSDK 3.1.6 #C .net 3.5 :

        public static void MoveFiles()
        {
            BasicAWSCredentials basicCredentials = new BasicAWSCredentials("your access key", "your secret key");
            AmazonS3Config configurationClient = new AmazonS3Config();
            configurationClient.RegionEndpoint = RegionEndpoint.EUCentral1;
            try
            {
                using (AmazonS3Client clientConnection = new AmazonS3Client(basicCredentials, configurationClient))
                {
                    S3DirectoryInfo source = new S3DirectoryInfo(clientConnection, "sourcebucketname", "sourcefolderkey");
                    S3DirectoryInfo target = new S3DirectoryInfo(clientConnection, "targetbucketname", "destinationbucketname");
                    source.CopyTo(target);

                }
            }
            catch(Exception ex)
            {

            }



        }
于 2016-06-24T21:00:43.743 回答