[Rails] Image upload problems

Lars Pind lars at pinds.com
Wed Jan 5 00:04:02 GMT 2005


Hi Berndt,

> So, like others on this list, I have started a picture store app.  I
> have followed the directions in the "how to" section for file uploads,
> as well as the previous posters here.  Basically, it seems as though
> it should be working, but the images become corrupt.  I can view them,

There as until recently (0.9.2, I believe) a bug in the MySQL driver, 
which would cause binary data to be corrupted when transferred to 
MySQL. Make sure you're on the latest version.

Another thing to check: Make sure your BLOB field is big enough. 
Mediumblob holds 16Mb, so that should be alright.

Finally, I noticed this in your code:

>    @params.delete("photo" => "tmp_file")

This shouldn't do any harm, but I'm not sure what good it does, either. 
What did you intend it to do?

>       redirect_to :action => "show/" + @photo.id.to_s

This can be tightened up a bit, by saying

redirect_to :action => "show", :id => @photo.id

Good luck,
/Lars



More information about the Rails mailing list