# File Upload Problems

**URL:** <https://www.ruby-forum.com/t/file-upload-problems/92960>\
**Category:** Rails\
**Created:** [April 26, 2007, 2:00am UTC](https://www.ruby-forum.com/t/file-upload-problems/92960 "2007-04-26T02:00:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 26, 2007, 2:00am UTC](https://www.ruby-forum.com/t/file-upload-problems/92960/1 "2007-04-26T02:00:43Z")

</div>

I am obviously doing something wrong when implementing the rubyonrials  
wiki code for uploading a file.

I don’t seem to be getting the actual file object included with the  
form, as it complains about trying to call read on a string object.

How do I get the actual file that was uploaded?

Here is my code:

Controller

def auto  
if request.post?  
@sched = Schedule.new  
@sched.automate(params[:schedule])  
end  
end

Model

def automate(schedule)  
File.open(“schedule\_store/#{schedule[‘filename’]}”, “w”) { |f|  
f.write(schedule[‘filename’].read) }  
end

View

**Schedule:**

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 26, 2007, 11:13am UTC](https://www.ruby-forum.com/t/file-upload-problems/92960/2 "2007-04-26T11:13:28Z")

</div>

I have had great success with acts\_as\_attachment plugin.

:ivor

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 26, 2007, 6:38pm UTC](https://www.ruby-forum.com/t/file-upload-problems/92960/3 "2007-04-26T18:38:08Z")

</div>

Figured out how to get my file uploaded although I can’t access the  
origional\_filename now. This is starting to frustrate me. I don’t  
really want or need all the extra stuff included in acts\_as\_attachment  
and I have to interact with it via the commandline, RadRails hasn’t  
fixed their server problem yet (been a month now) so I can’t update  
plugins through Eclipse.

If anyone could help me get this working that would be fantastic.  
Here is the new code which uploads the file but won’t let me get the  
filename (I have to give it a generic name).

Model  
def self.automate(schedule)  
@file\_name = “test”  
schedule[:schedule\_file].rewind  
File.open(“schedule\_store/#{@file\_name}”, “w”) { |f|  
f.write(schedule[:schedule\_file].read) }  
end

Controller  
def auto  
if request.post?  
@sched = Schedule.automate(params[:schedule])  
end  
end

View  
\<% form\_for(:schedule, @schedule, :url =\> {:action =\> ‘auto’}, :html  
=\> {:multipart =\> true}) do |form| %\>

**Schedule:** \<%= form.file\_field :schedule\_file %\>

 \<%= submit\_tag "Auto" %\> \<% end %\>

Thanks,  
Glen
