Data type of input type file

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

Is your form set to be multipart ?

Fred

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

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

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

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

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 Fiddler | Web Debugging Proxy and Troubleshooting Solutions These are http proxies that
let you inspect all the traffic being passed through.

Fred