views:

160

answers:

2

I want to create an instance of "uploaded_file = ActionController::UploadedTempfile" from a File.new("path/to/file"), and then go on to do processing on "uploaded_file" like so:

uploaded_file = ActionController::UploadedTempfile.new(File.new "path/to/file").

But for everything to work correctly, I need to set it so that uploaded_file.original_filename method and uploaded_file.content_type methods work correctly. How do i assign its variables so that it works?

A: 

you can set content_type by simply assigning, and to set original_filename, you can do

obj.instance_variable_set "@original_filename", "whatyouwant"
A: 

hello sheikh,

iam having the same problem statement as described by you

"I need to enable a user to preview an image he wants to upload, and this upload is part of a form that needs to be filled. When the form is filled correctly, the image also gets uploaded if present, otherwise, nothing happens. i want him to be able to preview image before submitting form independently, so when he presses preview, file is uploaded and path is saved in session, when he fills form and submits, the image is also saved but file name has to be read from session. i want old code that does validating before saving to stay untouched, so i wanna give it afile as if it wre in attachment "

can u pls lemme know how you solved this issue with clear code for controller and views of the model. Pls help asap

nisha
u can check out http://pastie.org/1083827 i hope it helps. not a clean solution, but it worked!