If I have a form that includes something like: <input type="file" name="file_content" /> and I try to get at the file content using: params[''file_content''].read I get: undefined method `read'' for "filename":String where "filename" is the *NAME* of the file that was assigned to "file_content" in the input tag. Apparently Ruby thinks my file is a string and that consequently it has no ''read'' method. What am I doing wrong and how can I get at the actual file content? Thanks for any input. ... doug --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
On 8 Jul 2008, at 02:55, doug wrote:> > If I have a form that includes something like: > > <input type="file" name="file_content" /> > > and I try to get at the file content using: > > params[''file_content''].read > > I get: > > undefined method `read'' for "filename":String > > where "filename" is the *NAME* of the file that was assigned to > "file_content" in the input tag. > > Apparently Ruby thinks my file is a string and that consequently it > has no ''read'' method. What am I doing wrong and how can I get at the > actual file content?Is your form set to be multipart ? Fred --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
> Is your form set to be multipart ?Great thought and it would have really been embarrassing if that had turned out to be the case; but, it wasn''t. I do have the form set to multipart with the following attribute to the form tag: enctype="multipart/form-data" I thought this was going to be some really obvious stupid error on my part like the one you suggested and I thought someone would likely point it out to me within a few minutes of my post. I guess that''s not the case. Now, I''m beginning to think that I don''t understand exactly what it is that comes back in the params hash as a result of having a <input type="file"> tag in the form. If someone could enlighten me on that, it would be great. Thanks for the input. ... doug --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
On 8 Jul 2008, at 17:11, doug wrote:> >> Is your form set to be multipart ? > > Great thought and it would have really been embarrassing if that had > turned out to be the case; but, it wasn''t. I do have the form set to > multipart with the following attribute to the form tag: > > enctype="multipart/form-data" >Have you verified in the browser that the expected html is generated? Have you looked with a packet sniffer to see if the file is being sent to the server? Fred> I thought this was going to be some really obvious stupid error on my > part like the one you suggested and I thought someone would likely > point it out to me within a few minutes of my post. I guess that''s > not the case. Now, I''m beginning to think that I don''t understand > exactly what it is that comes back in the params hash as a result of > having a <input type="file"> tag in the form. If someone could > enlighten me on that, it would be great. > > Thanks for the input. > > ... doug > >--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for your input and patience, Fred. As is usually the case in these types of situations, the problem turned out to be a factor that I didn''t deem as being relevant. That factor is that access is being controlled by sessions. The brief explanation is that I made my form by using straight HTML rather than the Rails helpers. Without going into all of the gory details, one needs to use the Rails helpers in this case. I now have it working. Thanks for the input. ... doug --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Jul-09 13:59 UTC
Re: Data type of input type file
Master Cheung, I see you mention a ''packet sniffer''. What is that and how does one implement one? I am grateful for any explanation. Thank you, Kathleen On Jul 8, 10:18 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 8 Jul 2008, at 17:11, doug wrote: > > > > >> Is your form set to be multipart ? > > > Great thought and it would have really been embarrassing if that had > > turned out to be the case; but, it wasn''t. I do have the form set to > > multipart with the following attribute to the form tag: > > > enctype="multipart/form-data" > > Have you verified in the browser that the expected html is generated? > Have you looked with a packet sniffer to see if the file is being sent > to the server? > > Fred > > > I thought this was going to be some really obvious stupid error on my > > part like the one you suggested and I thought someone would likely > > point it out to me within a few minutes of my post. I guess that''s > > not the case. Now, I''m beginning to think that I don''t understand > > exactly what it is that comes back in the params hash as a result of > > having a <input type="file"> tag in the form. If someone could > > enlighten me on that, it would be great. > > > Thanks for the input. > > > ... doug--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 9 Jul 2008, at 14:59, KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> > Master Cheung, > I see you mention a ''packet sniffer''. What is that and how does one > implement one?It''s a piece of software that dumps/displays all the packets going through your machine (usually with the ability to filter based on a set of conditions so that you can narrow it down to what you''re trying to observe) Eg tcpdump, wireshark (formally ethereal) etc.. On unixy platforms, there are a set of ruby bindings for libpcap (the library that tcpdump uses) if you feel like doing your packet sniffing from ruby. Slightly different, but also interesting are things like http://www.charlesproxy.com/ and http://www.fiddlertool.com/fiddler/ These are http proxies that let you inspect all the traffic being passed through. Fred> > I am grateful for any explanation. > Thank you, > Kathleen > > On Jul 8, 10:18 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> On 8 Jul 2008, at 17:11, doug wrote: >> >> >> >>>> Is your form set to be multipart ? >> >>> Great thought and it would have really been embarrassing if that had >>> turned out to be the case; but, it wasn''t. I do have the form set >>> to >>> multipart with the following attribute to the form tag: >> >>> enctype="multipart/form-data" >> >> Have you verified in the browser that the expected html is generated? >> Have you looked with a packet sniffer to see if the file is being >> sent >> to the server? >> >> Fred >> >>> I thought this was going to be some really obvious stupid error on >>> my >>> part like the one you suggested and I thought someone would likely >>> point it out to me within a few minutes of my post. I guess that''s >>> not the case. Now, I''m beginning to think that I don''t understand >>> exactly what it is that comes back in the params hash as a result of >>> having a <input type="file"> tag in the form. If someone could >>> enlighten me on that, it would be great. >> >>> Thanks for the input. >> >>> ... doug > >--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---