Copying a file inside an S3 bucket (ruby)

I am using gem aws-sdk-ruby and I want to copy the file / images / image _a.png to / profile.png all of which are inside the same bucket.

How can i do this?

+7
source share
2 answers

Extracted from the documentation , you will need to use copy_to . For example:

 s3 = AWS::S3.new # Upload a file and set server-side encryption. bucket1 = s3.buckets[source_bucket] bucket2 = s3.buckets[target_bucket] obj1 = bucket1.objects[source_key] obj2 = bucket2.objects[target_key] obj1.copy_to(obj2) 
+6
source

to do this with aws-sdk-v2 you can do the following:

 bucket = Aws::S3::Bucket.new('my_aws_bucket') new_object = bucket.object("new_photo_uploads/logos/my_new_copied_photo.png") aws_response = new_object.copy_from(bucket.object("my_original_photo.png")) 
+3
source

All Articles