Anil Wadghule
2006-Sep-07 13:50 UTC
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 =@params["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 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Greg Donald
2006-Sep-07 14:18 UTC
Re: How to get the finename of the file taken from file_field?
On 9/7/06, Anil Wadghule <anildigital-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Anthony Carlos
2006-Sep-07 14:35 UTC
Re: How to get the finename of the file taken from file_field?
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 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#<StringIO:0x369dda8>" 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---