deb deb - 6 months ago 35
Ruby Question

How to copy file across buckets using aws-s3 gem

The aws-s3 documentation says:

# Copying an object
S3Object.copy 'headshot.jpg', 'headshot2.jpg', 'photos'


But how do I copy
heashot.jpg
from the
photos
bucket to the
archive
bucket for example

Thanks!

Deb

deb deb
Answer

Using the right_aws gem:

# With s3 being an S3 object acquired via S3Interface.new
# Copies key1 from bucket b1 to key1_copy in bucket b2:
s3.copy('b1', 'key1', 'b2', 'key1_copy')

the gotcha I ran into is that if you have pics/1234/yourfile.jpg the bucket is only pics and the key is 1234/yourfile.jpg

I got the answer from here: http://stackoverflow.com/questions/769848/how-do-i-copy-files-between-buckets-using-s3-from-a-rails-application

Comments