List Info

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




How to get the finename of the file taken from file_field?
user name
2006-09-07 13:50:56
I have used

<%= file_field "file", "picture"%&gt; in my form.

In the controller side I have taken filename =params[&quot;file&quot;]

But I am getting "picture#<StringIO:0x369dda8>&quot; in the filename.

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

Regards,
Anil Wadghule
--
Don't live to geek; geek to live.
http://anildigital.blogspot.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talkgooglegroups.com
To unsubscribe from this group, send email to rubyonrails-talk-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---

How to get the finename of the file taken from file_field?
user name
2006-09-07 14:18:38
On 9/7/06, Anil Wadghule <anildigitalgmail.com> wrote:
> I have used
>
> <%= file_field "file",
"picture"%> in my form.
>
> In the controller side I have taken filename
=params["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 Donald
http://destiney.com/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talkgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribegooglegroups.com
For more options, visit this group at http:
//groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---

How to get the finename of the file taken from file_field?
user name
2006-09-07 14:35:15
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:


Hope it helps,

-Anthony

On Sep 7, 2006, at 9:50 AM, Anil Wadghule wrote:

I have used

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

In the controller side I have taken filename =params["file"]

But I am getting "picture#&lt;StringIO:0x369dda8&gt;" in the filename.

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

Regards,
Anil Wadghule
--
Don't live to geek; geek to live.
http://anildigital.blogspot.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talkgooglegroups.com
To unsubscribe from this group, send email to rubyonrails-talk-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )