Very simple file upload in Rails.

I made a very simple file upload page in Rails so my friend could send me some images from her camera in a zip file.

In app/views/file_upload/index.erb:


<% form_tag '/file_upload/upload', :multipart => true do %>
<%= file_field_tag "file" %><br>
<%= submit_tag "Submit" %><% end %>

In app/controllers/file_upload_controller.rb:


class FileUploadController < ApplicationController
def index
end

def upload
file = params["file"]
name = file.original_filename
File.open(File.join("/media/sdb1/dropbox", name), "wb") { |f| f.write(file.read) }
render :text => "Wrote #{name}, complete!"
end
end

Obviously this is not meant for production; it is just a dumb way to transfer a file over the web. In particular, you should probably use some sort of chroot jail or verification of filename so the program cannot touch files outside the desired directory.