2

I have a file in aws S3 that I want to copy to an active record paperclip attachment (as a copy of the file in a different bucket).

I have a reference to the object on S3 using the aws-sdk gem:

s3 = AWS::S3.new(Rails.application.config.s3_creds)
obj = s3.buckets(uploads_bucket).objects.first

Say my active record model my_model has

has_attached_file :some_file

How do I copy obj into my_model.some_file ?


my_model.some_file = obj throws: No handler found for AWS::S3::S3Object:bucket/the_file.xls

obj.copy_to(my_model.some_file) throws undefined method `scan' for /file_name/original/missing.png:Paperclip::Attachment

4

1 回答 1

0

I'm copying the file using AWS::S3::S3Object#copy_to(target_obj) and I get target obj by calling #s3_object() on the attachment after setting some column values and saving it:

my_model.some_file_file_name = obj.key
my_model.some_file_file_size = obj.content_length
my_model.some_file_content_type = obj.content_type
my_model.some_file_updated_at = obj.last_modified
my_model.save

obj.copy_to(my_model.some_file.s3_object)
于 2013-04-30T22:57:55.210 回答