Duplicating a Paperclip attachment without running processors?

74 views
Skip to first unread message

Walter Lee Davis

unread,
Aug 9, 2013, 5:15:58 PM8/9/13
to rubyonra...@googlegroups.com
I need to duplicate an object that has an attached Paperclip file. This file (depending on its file-type) may have two to four different styles, with separate file-processing stages required for each. Some of these involve transcoding in FFMPEG, so I would really rather not run the processors all over again, when the various re-coded versions already exist on S3.

The naive thing (which I have done, and works) is simply to create a new object, open the original file from S3 using open-uri, and run the process over again. This works, but takes a long time, since some of these movie files are large and the processing steps to make thumbnails and poster frames are weighty.

Searching for solutions on this, I came across the dup method, and I also saw a dup method on the Paperclip attachment when I inspected its methods. Before I go into a lengthy yak-shaving exercise here, can anyone point me to a simpler way to manage what I am trying to accomplish here? Essentially I want to duplicate a group of files in place on S3 (yes, I realize you can't do that without copying them) but I want to skip all the processing steps and just duplicate the styles "manually".

Thanks in advance,

Walter

Walter Lee Davis

unread,
Aug 12, 2013, 12:13:02 PM8/12/13
to rubyonra...@googlegroups.com
Replying to my own, since I posted after beer-thirty on Friday.
Here's another thing I have found: http://blog.firsthand.ca/2011/07/ruby-script-to-duplicate-s3-bucket.html which is to duplicate an entire bucket. I'm not sure of my terminology here, is a bucket always the outermost container, or is it any level of "directory" in a named bucket? I've been reading the source of right_aws here: https://github.com/rightscale/right_aws/blob/master/lib/s3/right_s3.rb and there is a copy_key method that looks useful, but I am leery of creating a duplicate Paperclip object without involving Paperclip. Is the relationship between an attachment and all of its versions merely predicated on the file paths? Is there any metadata stored elsewhere that I would also need to duplicate?

Thanks,

Walter

>
> Thanks in advance,
>
> Walter
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/930C9291-C70A-44B1-8ADE-932327D2D0CE%40wdstudio.com?hl=en-US.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Reply all
Reply to author
Forward
0 new messages