Image upload problem.

I’ve seen posts of a few people who have this problem, but not a single response about solving it.

I can’t upload .png files, but .jpg and .gif work fine. When I upload just a .png, my action gets a StringIO object which breaks when I try to copy the upload to an absolute location. However, using multiple-field upload, as long as one of the to-upload files is not a .png, all of the png files will properly upload (TempFile objects now). So:

Upload: test_image.png → Failure (FileUtils evaluating nil.to_str in #cp)

Upload: test_image1.png, test_image2.png → Also fails

Upload: test_image1.png, test_image2.png, test_image3.jpg → Works perfectly, I see all three images.

So, what’s going on with Rails and png? Is there a mime type I’m missing somewhere? It just doesn’t make any sense.

Thanks

Jason

Found out where the problem is, and it’s just coincidence that PNG images were showing this problem.

I’ve found the problem in but one place: http://blog.vixiom.com/2006/07/26/rails-stringio-file-upload/

In short: file uploads that are less than a certain threshold (15K?) become StringIO objects, and anything larger is a Tempfile. I thought all would be Tempfiles.

Then I checked out file_column (http://opensvn.csie.org/rails_file_column/plugins/file_column/) and found this bit of code:

# stored uploaded file into local_file_path
      # If it was a Tempfile object, the temporary file will be
      # cleaned up automatically, so we do not have to care for this
      if file.respond_to?(:local_path) and file.local_path and File.exists?(file.local_path)
        FileUtils.copy_file(file.local_path, local_file_path)
      elsif file.respond_to?(:read)
        File.open(local_file_path, "wb") { |f| f.write
(file.read) }
      else
        raise ArgumentError.new("Do not know how to handle #{file.inspect}")
      end

So somewhere in Rails (this problem is with both WEBrick and Mongrel, so I’m assuming it’s not them) there’s logic to turn upload file data into a tempfile after a certain size, but I cannot find out where. Would it be possible / feasible to make all file uploads Tempfiles or is this not possible to know on the server?

Jason