Amazon.S3.AmazonS3Client.CopyObject C# (CSharp) Method

CopyObject() public method

Creates a copy of an object that is already stored in Amazon S3.
public CopyObject ( CopyObjectRequest request ) : CopyObjectResponse
request Amazon.S3.Model.CopyObjectRequest Container for the necessary parameters to execute the CopyObject service method.
return Amazon.S3.Model.CopyObjectResponse
        public CopyObjectResponse CopyObject(CopyObjectRequest request)
        {
            var marshaller = new CopyObjectRequestMarshaller();
            var unmarshaller = CopyObjectResponseUnmarshaller.Instance;

            return Invoke<CopyObjectRequest,CopyObjectResponse>(request, marshaller, unmarshaller);
        }

Same methods

AmazonS3Client::CopyObject ( string sourceBucket, string sourceKey, string destinationBucket, string destinationKey ) : CopyObjectResponse
AmazonS3Client::CopyObject ( string sourceBucket, string sourceKey, string sourceVersionId, string destinationBucket, string destinationKey ) : CopyObjectResponse

Usage Example

Example #1
0
        public static void SoftDeleteFolders(ControllerConfiguration context, IEnumerable<string> folders)
        {
            if (context == null)
                throw new ArgumentNullException("context", "Context cannot be null.");
            if (folders == null)
                throw new ArgumentNullException("folders", "Folders cannot be null.");

            using (var client = new AmazonS3Client(context.AwsAccessKeyId, context.AwsSecretAccessKey))
            {
                foreach (var folder in folders)
                {
                    int maxResults = 100;
                    int lastCount = maxResults;
                    while (maxResults == lastCount)
                    {
                        using (var listResponse = client.ListObjects(new ListObjectsRequest()
                        {
                            BucketName = context.BucketName,
                            Prefix = folder,
                        }))
                        {
                            lastCount = listResponse.S3Objects.Count;

                            Parallel.ForEach(listResponse.S3Objects, folderObject =>
                                {
                                    using (var copyResponse = client.CopyObject(new CopyObjectRequest()
                                    {
                                        SourceBucket = context.BucketName,
                                        DestinationBucket = context.BucketName,
                                        SourceKey = folderObject.Key,
                                        DestinationKey = ".recycled/" + folderObject.Key,
                                    })) { }
                                });

                            Parallel.ForEach(listResponse.S3Objects, folderObject =>
                                {
                                    using (var deleteReponse = client.DeleteObject(new DeleteObjectRequest()
                                    {
                                        BucketName = context.BucketName,
                                        Key = folderObject.Key,
                                    })) { }
                                });
                        }
                    }
                }
            }
        }
All Usage Examples Of Amazon.S3.AmazonS3Client::CopyObject
AmazonS3Client