File upload problems when moving application to new server

I’m having some problems with file upload on my rails application.

Everything works as expecteded, except file upload. I can upload some
files (such as Word-documents), but others (such as InDesign-
documents) results in an error (type 500). I suspect this has
something to do with mime types (?), but don’t know where to start
fixing the problem. When getting an error, the application spits out
the contents of the file I’m trying to upload to the log file:

Processing DocumentController#upload (for xx.xx.xx.xx at 2007-12-21
14:45:48) [POST]
Session ID: (…)
Parameters: {“commit”=>“Upload”, “action”=>“upload”, “id”=>“111”,
“controller”=>“document”, “myfile”=>{“myfile”=>"…a lot to data
here …"}}
NoMethodError (undefined method `read’ for #String:0x237fb20):

I am currently moving the application to a new server, and the
everything worked OK on the old one. It is the new server that has
problems. Both machines uses the same rails application and
configuration files, and are having the following configuration:

Working server:
PowerMac (Quad Intel), running Mac OS X Tiger
Rails 1.2.3
Nginx web server
mongrel cluster with 3 processes

New server (with problem)
PoweMac G5, running Mac OS X Leopard
Rails 1.2.6 (could not install 1.2.3)
Nginx web server
mongrel cluster with 3 processes

The relevant code:


def upload

Get request => show the form

if request.get?
@myfile =
# Do the upload
@myfile =[:myfile])

# ... (Setting Myfile data here)

# Check if filename exists
if not Myfile.find_by_filename_and_folder_id(@myfile.filename,

@myfile.filename = @myfile.filename + ’ (’ +’%Y%m%d%H%M%S’) + ‘)’

  redirect_to(:controller => 'project', :action => 'show', :id =>

project_id, :folder_id => params[:folder_id])

==== VIEW ====

File upload

<% form_tag({:action => ‘upload’, :folder_id => controller.folder_id},
{:multipart => true}) do -%>
<%= error_messages_for(‘myfile’) %>
Choose file:

<%= file_field(‘myfile’, ‘myfile’) %>

<%= submit_tag ‘Upload’ %>
<% end -%>

==== MODEL ====

Save file to folder

def myfile=(myfile_field)
if myfile_field and myfile_field.length > 0
@date_time_created =
‘wb’) { |f| f.write( } # only save in the database
if this succeeds
self.filename =
filesize = (myfile_field.length / 1000).to_i
if filesize == 0
self.filesize = 1
self.filesize = filesize

I’m grateful for any help!

This issue was fixed when upgrading from Rails 1.2.6 to 2.0.2.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs