简体   繁体   中英

Copying multiple files from one bucket to another

In one request, I would like to be able to copy multiple files that are specific from one bucket to another. I have the standard code for a single file, which I have to iterate over and cause multiple requests in order to copy multiple files. Is there a way to give a list of files that I want copied over from one bucket to another, and do it in only one request? This is what my code looks like now:

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

由于存储桶的工作方式,我很确定没有办法在单个请求中进行批量复制。

I think you can use S3DirectoryInfo class and CopyTo method to copy the folder key between buckets. but it will perform one request for each file to move to target bucket and although it is more elegant way to do it.for example I used 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)
            {

            }



        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM