Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I recently built an application which accepts a large number of uploads on Heroku. I decided to build my own solution instead of using cloudinary or an equivalent. Here are some lessons I learned:</p> <ul> <li><p>Don't upload to heroku. Your entire web worker will be locked down for the entire duration of the upload. That's up to a minute. Unacceptable.</p></li> <li><p>Use a javascript uploader (like jquery-file-upload) to upload directly to s3. This is a little complicated at first, but once you get it working it's fantastic. You can use the <a href="https://github.com/waynehoover/s3_direct_upload" rel="noreferrer">s3_direct_upload</a> gem, or you can just read their source to make your own solution from scratch. That gem was based on a <a href="http://railscasts.com/episodes/383-uploading-to-amazon-s3" rel="noreferrer">railscasts pro</a> episode, which you have to pay for, but has <a href="https://github.com/railscasts/383-uploading-to-amazon-s3" rel="noreferrer">source available</a>.</p></li> <li><p>When the upload finishes, make an ajax request to your application passing the new s3 url as a <a href="https://github.com/jnicklas/carrierwave#uploading-files-from-a-remote-location" rel="noreferrer">remote url</a>. Carrierwave will then process the image on s3 like it was uploaded, except in only a couple seconds instead of up to a minute.</p></li> <li><p>Use jquery-file-upload's <a href="https://github.com/blueimp/jQuery-File-Upload/wiki/API#image-resizing" rel="noreferrer">client-side image resizing</a>. Somebody's going to try to upload a 5MB photo and then bitch that the upload takes forever. This will make all uploads as fast as theoretically possible.</p></li> <li><p>Configure s3 to <a href="http://docs.aws.amazon.com/AmazonS3/latest/UG/LifecycleConfiguration.html" rel="noreferrer">clear your uploads folder automatically</a>.</p></li> <li><p>Don't use thin. Use <a href="https://devcenter.heroku.com/articles/rails-unicorn" rel="noreferrer">unicorn</a>. A couple seconds is too long to be processing a request on thin, but unicorn with three or four workers is much more forgiving.</p></li> <li><p>Don't use rmagick. It's a better API for complex image manipulation but uses amazing amounts of memory. Use mini_magick instead.</p></li> </ul> <p>You'll note that I'm not using a background worker for any of this. If you're really feeling meticulous, you could have the controller that receives the remote url pass its work to a background worker, and if you need the result immediately the background worker could notify the UI by pubsub (faye or pusher, possibly with the exciting new <a href="https://github.com/chrismccord/sync" rel="noreferrer">sync</a> gem). But this wasn't necessary for my application, and I'd rather spend my money on another web dyno than a worker dyno.</p> <p>And, yeah, if you want to let them click around your whole application while that's happening, you're going to need to either be uploading in a popup (and using some kind of pubsub solution), or building your whole site as a javascript application using ember or backbone or angular or whatever.</p> <p>Any questions?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload