how to read a User uploaded file, without saving it to the database
Posted
by GoodGets
on Stack Overflow
See other posts from Stack Overflow
or by GoodGets
Published on 2010-03-26T03:56:06Z
Indexed on
2010/03/26
4:03 UTC
Read the original article
Hit count: 439
I'd like to be able to read an XML file uploaded by the user (less than 100kb), but not have to first save that file to the database. I don't need that file past the current action (its contents get parsed and added to the database; however, parsing the file is not the problem). Since local files can be read with:
File.read("export.opml")
I thought about just creating a file_field for :uploaded_file, then trying to read it with
File.read(params[:uploaded_file])
but all that does is throw a TypeError (can't convert HashWithIndifferentAccess into String). I really have tried a lot of various things (including reading from the /tmp directory as well), but could get none of them to work.
I hope the brevity of my question doesn't mask the effort I've given to try to solve this on my own, but I didn't want to pollute this question with a hundred ways of how NOT to get it done. Big thanks to anyone who chimes in.
© Stack Overflow or respective owner