I’ve been experimenting a good bit with Ruby on Rails’ file upload capabilities. Overall I’ve been very impressed with the ease of use when it comes to uploading a file and writing it to disk. Of course anything is easy once you know how. Ruby’s syntax is very different than what you’re probably used to. While I’m by no means an expert on the subject I would definitely recommend the following books:
Programming Ruby: The Pragmatic Programmers’ Guide
Agile Web Development with Rails
After digging up the necessary code I was able to experiment with ROR’s file upload capabilities. My method called create was attached to my controller and looked like:
def create
File.open(“/Users/db/_dev/rails/videos/swing.mov”, “w”){|f|f.write(@params["video"].read)}
end
With that one line of code the file was written to disk….not too shabby. It’s right up there with ColdFusion’s CFFILE which has a much cleaner tag-based approach. At any rate, using this method allowed me to upload all sorts of photos and videos with ease.
I then proceeded to strain the server a little bit. When I say server ROR is running locally on my Powerbook. I grabbed a 175MB video file and put it to the test. The upload took almost 5 minutes to complete and during this time the output of top displayed ROR’s CPU utilization at about 80%. Pretty heavy lifting, but the upload competed successfully and I was able to view the uploaded file without any hiccups.
Read More