views:

238

answers:

2

I'd like to be able to upload a zip file to my Rails application that contains a number of images. Then I'd like Rails to unzip that file and attach the images inside to my Photo's model via Paperclip, so that they are ultimately stored on my Amazon S3 account (configured through Paperclip).

I'd like do do this all on my Rails site hosted on Heroku, which unfortunately doesn't allow local storage of any kind (so far as I'm aware) to temporarily do the unzipping before the Paperclip parsing.

How would I do this??

+1  A: 

Heroku does allow writing to #{RAILS_ROOT}/tmp.

But you need to take in mind that file will be there only as long as request lasts. Probably longer, but that is not guaranteed. You could try to block request while you unzip and send to S3, but you should take care of the time it takes.

It sounds to me like you need some flash uploader that can unzip and send to S3, without Heroku.

dmajkic
But would I be able to still make my Paperclip associations in my Rails app if I used a flash uploader that bypassed Heroku? Bit confused here.
neezer
There's a bit here about dealing with existing files after you migrate your DB to use papercliop. You can literally just set your model.attachment to a file as listed there. Might help you in what you're trying to do: http://thewebfellas.com/blog/2008/11/2/goodbye-attachment_fu-hello-paperclip
Joost Schuur
A: 

dmagkic is correct about the rails_root/tmp. I recommend something like the following:

  • Upload files through heroku to S3
  • Setup a background job to zip the files (store the file names that you need to group)
  • run the BJ that downloads the files from S3, zips them, sends the zip to S3, removes the unzipped files.

That way your application will still be responsive'ish during the upload process.

If you try to upload multiple files, you COULD write to /tmp, but just make sure that all the files come across in the same post request.

Jesse Wolgamott
You have things reversed: I want to *upload a zip file* and have Rails *store the unzipped files*. I'm still unclear about how long I have to work with the files in `#{RAILS_ROOT}/tmp`, though: do they persist until the next request comes through or do they expire sooner than that? And does the request have to be for the same action or any request to the application?
neezer
OK, just change things around a bit. Upload the ZIP to S3 using paperclip and do a background job to unzip and process the files. A Request is 1 HTTP action, you have no more time in /tmp than that.
Jesse Wolgamott