How can I do a large file upload using Sinatra, haml, nginx, and passenger?

Posted by mmr on Server Fault See other posts from Server Fault or by mmr
Published on 2010-02-10T22:01:40Z Indexed on 2010/05/21 7:50 UTC
Read the original article Hit count: 315

Filed under:

Hi all,

I need to be able to allow a user to upload 30-60 mb files at a time. Right now, I'm solving the problem with a simple form post:

%form{:action=>"/Upload",:method=>"post",:enctype=>"multipart/form-data"}
 - @theModelHash.each do |key,value|
   %br
   %input{:type=>"checkbox", :name=>"#{key}", :value=>1, :checked=>value}
   =key
 %br    
%input{:type=>"file",:name=>"file"}
%input{:type=>"submit",:value=>"Upload"}

This form allows the user to select processing options contained in theModelHash and upload a file for processing. Problem is, this method both freezes the user's UI and also requires that the entire form be reposted when the user presses the 'back' button.

I've looked at SWFUpload, but have no idea how to integrate that into my relatively simple app. There's a page here about integrating it with Rails, but I'm using Sinatra, and am new enough to this whole web programming thing that I don't know how to modify those files to work with what I need to do.

Is there a how-to to add large file uploads to my form there? Something relatively simple that just adds in a progress bar and doesn't repost? I feel like I'm having to triple the size of my application just to make this feature play nice, and that's bothering me a bit.

© Server Fault or respective owner

Related posts about file-upload