How to get the finename of the file taken from file_field?

I have used

<%= file_field “file”, “picture”%> in my form.

In the controller side I have taken @filename [email protected][“file”]

But I am getting “picture#StringIO:0x369dda8” in the @filename.

How can i get the filename of that file in a string instead of hash?

Regards,
Anil W.

Don’t live to geek; geek to live.
http://anildigital.blogspot.com

On 9/7/06, Anil W. [email protected] wrote:

I have used

<%= file_field “file”, “picture”%> in my form.

In the controller side I have taken @filename [email protected][“file”]

Just params, not @params.

params[:file][:picture] should contain what you’re after.

But I am getting “picture#StringIO:0x369dda8” in the @filename.

How can i get the filename of that file in a string instead of hash?

picture.original_name should work on an uploaded file.

You may want to check out the file_column plugin if you have not
already:
http://www.kanthak.net/opensource/file_column/


Greg D.
http://destiney.com/

Anil:

In your model object, use self.picture.original_filename

I’m assuming your model object is: “file.rb”. It has an attribute
called “picture” which you have created for the form. “picture” has a
method called “original_filename” that returns a class of StringIO or
FileIO. StringIO (or FileIO, if the upload is big), automagically
gets a few variables set by the CGI class. The others are
“content_type”, “length”, and “read”.

See the note after the CGI class documentation in this link:

http://wiki.rubyonrails.org/rails/pages/HowtoUploadFiles

Hope it helps,

-Anthony