Rails does not block on file uploads
Published over 3 years ago
I’ve been quite annoyed with the ignorance of people who keep telling every other person that Rails/Mongrel blocks on file upload.
Here are the steps to realize Rails does not block on file uploads :
null:Rails lifo$ rails fileuploads null:Rails lifo$ cd fileuploads/ null:fileuploads lifo$ script/generate controller upload index
Make your RAILS_ROOT/app/views/upload/index.html.erb look something like below :
<% form_tag({}, { :multipart => true }) do %> <label for="file">File to Upload</label> <%= file_field_tag "file" %> <%= submit_tag %> <% end %>
Now, generate a big fat file ( YMMV ) for testing purpose :
null:fileuploads lifo$ dd if=/dev/random of=out.txt bs=1000000 count=100
In all fairness, you may notice a momentary spike in memory/cpu usage while dealing with very large file uploads ( we’re talking a good 100s of MB here ) But believing that Rails process is blocked for the entire time it takes a user to upload the file from the browser, is outrageous.