# Newbie: Can't get file to upload

**URL:** <https://www.ruby-forum.com/t/newbie-cant-get-file-to-upload/54722>\
**Category:** Rails\
**Created:** [March 13, 2006, 6:14pm UTC](https://www.ruby-forum.com/t/newbie-cant-get-file-to-upload/54722 "2006-03-13T18:14:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [March 13, 2006, 6:14pm UTC](https://www.ruby-forum.com/t/newbie-cant-get-file-to-upload/54722/1 "2006-03-13T18:14:32Z")

</div>

Since I can’t get the fancy upload progress thing to work, I thought  
that I would revert back to a regular file upload scenario.

I have a very simple file upload form set up. It appears that my file  
parameter is coming into the controller as a string, not a file object.

Here’s my view:

\<%= form\_tag :action =\> ‘save\_HTML’,  
:multipart =\> ‘true’ %\>  
\<%= file\_field ‘eSimplyJob’, ‘file’ %\>

\<%= submit\_tag "Upload" %\>

\<%= end\_form\_tag %\>

Here’s my controller method:

public  
def save\_HTML  
@filename = @params[:eSimplyJob][:file].original\_filename  
File.open("#{RAILS\_ROOT}/htmlfiles/#{@filename}", “wb”) do |f|  
f.write(@params[:eSimplyJob][:file].read)  
end  
puts “Finished with save\_HTML”  
end

When I execute the upload, I get the following error:

undefined method `original\_filename’ for “upload.rhtml”:String

I understand that this means that @params[:eSimplyJob][:file] is a  
String and not an IO object.

What am I doing wrong?

Thanks for any help.

Wes G.

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [March 13, 2006, 6:22pm UTC](https://www.ruby-forum.com/t/newbie-cant-get-file-to-upload/54722/2 "2006-03-13T18:22:08Z")

</div>

Well, I feel dumb.

I’ve decided to be very explicit about function call parens and the hash  
specifications for parameters.

Doing this:

\<%= form\_tag ({ :action =\> ‘save\_HTML’ },  
{ :multipart =\> ‘true’ }) %\>

works fine.

Thanks,  
Wes

Wes G. wrote:

> Since I can’t get the fancy upload progress thing to work, I thought  
> that I would revert back to a regular file upload scenario.
> 
> I have a very simple file upload form set up. It appears that my file  
> parameter is coming into the controller as a string, not a file object.
> 
> Here’s my view:
> 
> \<%= form\_tag :action =\> ‘save\_HTML’,  
> :multipart =\> ‘true’ %\>  
> \<%= file\_field ‘eSimplyJob’, ‘file’ %\>
> 
> \<%= submit\_tag "Upload" %\>
> 
> \<%= end\_form\_tag %\>
> 
> Here’s my controller method:
> 
> public  
> def save\_HTML  
> @filename = @params[:eSimplyJob][:file].original\_filename  
> File.open("#{RAILS\_ROOT}/htmlfiles/#{@filename}", “wb”) do |f|  
> f.write(@params[:eSimplyJob][:file].read)  
> end  
> puts “Finished with save\_HTML”  
> end
> 
> When I execute the upload, I get the following error:
> 
> undefined method `original\_filename’ for “upload.rhtml”:String
> 
> I understand that this means that @params[:eSimplyJob][:file] is a  
> String and not an IO object.
> 
> What am I doing wrong?
> 
> Thanks for any help.
> 
> Wes G.

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [March 15, 2006, 6:33am UTC](https://www.ruby-forum.com/t/newbie-cant-get-file-to-upload/54722/3 "2006-03-15T06:33:56Z")

</div>

Hey Wes,  
Can you help me if I ask you to make the uploading restricted to only  
doc files?  
Since you are half way already, I think you’ll be able to guess what I  
am talking about.  
Thanks in advance.
