Rails handles file uploads in the same way as any web infrastructure: it leaves file processing on the web server you use (Apache, Nginx, etc.). Then, when the file download is complete, it gives your structure the location (usually a temporary file) of the downloaded file (and the like, the MIME type). You decide what to do with this file. Rails does this by providing you with a Ruby File object in your controller.
If you use a gem such as "paperclip", it gives you a bit more control over the files out of the box, instead of just processing it yourself, you can have automatic image resizing or other hooks for later downloading, it is really worth exploring.
If you decide to do it yourself, you will need a controller code that takes a File object (temp file) and writes it to another location. So, if you have a multi-part web form that takes a file:
<%= form_tag({:action => :upload}, :multipart => true) do %> <%= file_field_tag 'picture' %> <% end %>
In the params hash, you get a picture object:
params[:picture]
This is a temporary file. Rails provides two additional methods for determining the original file name and MIME type:
params[:picture].original_filename params[:picture].content_type
source share