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.
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.
Sorry, I can’t picture what you’re doing. What is your “view” and your
“controller” code ?
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.
# 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?
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
Look in the ruby file cgi.rb, method “read_multipart”. This is part of
Ruby, not Rails.
On my Linux machine it is found in
/usr/lib/ruby/1.8/cgi.rb
Stephan
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.