handling file uploads

hey guys,

the way i'm handling file uploads is no good, but i'm not sure what the best way to go about it is. right now my approach is to use FileUtils.mv to move the uploaded file to the directory i want it in. this approach doesn't work well because sometimes the uploaded file is just an IO object instead of a temporary file (apparently small files aren't put into temp files according to the CGI documentation). anyway, how should i be doing this? i like just using 'mv' to move the files... is there a way i can force cgi to store everythng as a temporary file? i also tried using the IO#read method to read the uploaded files data into a new file, but that didn't seem to get the MIME-type and stuff in there... what should i do?

thanks, cam

hey guys,

the way i'm handling file uploads is no good, but i'm not sure what the best way to go about it is. right now my approach is to use FileUtils.mv to move the uploaded file to the directory i want it in. this approach doesn't work well because sometimes the uploaded file is just an IO object instead of a temporary file (apparently small files aren't put into temp files according to the CGI documentation). anyway, how should i be doing this? i like just using 'mv' to move the files... is there a way i can force cgi to store everythng as a temporary file?

yes, if you modify the cgi module

if you dont want to handle the workaround yourself, theres acts_as_attachment and file_column plugins..

i also tried using the IO#read method to read the

Cam wrote:

hey guys,

the way i'm handling file uploads is no good, but i'm not sure what the best way to go about it is. right now my approach is to use FileUtils.mv to move the uploaded file to the directory i want it in. this approach doesn't work well because sometimes the uploaded file is just an IO object instead of a temporary file (apparently small files aren't put into temp files according to the CGI documentation). anyway, how should i be doing this? i like just using 'mv' to move the files... is there a way i can force cgi to store everythng as a temporary file? i also tried using the IO#read method to read the uploaded files data into a new file, but that didn't seem to get the MIME-type and stuff in there... what should i do?

thanks, cam

Cam - I'd go with file_column plugin like Carmen said. Though I found it's documentation a little lacking, I've seen a few topics on this mailing list that should help you figure out how to use it. Once you figure it out (it's very simple, but not completely obvious without seeing a good example) it should be exactly what you are looking for.

-Ben Lisbakken

file_column looks really cool. it actually does way more than i need it to, and i don't like the places it's putting the files on the drive, but i should be able to modify that pretty easily. i don't really understand where in his code he's handling the stringio case, but i'll have to look over it more thoroughly.

thanks! cam