views:

128

answers:

2

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

+1  A: 

I believe that in order to copy between buckets you must read the file's contents from the source bucket and then write it back to the destination bucket via your application's memory space. There's a snippet showing this using aws-s3 here and another approach using right_aws here

bjg
I'd like to use the snippet for aws-s3 but I'm having problems initializing the AmazoneS3Asset class. Do I simply put the snippet that defines the class in config/initializers ?
deb
I found the answer to my comment here http://stackoverflow.com/questions/1146946/ruby-on-rails-and-external-classes
deb
apparently right_aws has this fucntionality, I didn't need to add the snippet. I posted more info in the answer below
deb
A: 

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

deb