# File upload error(can't convert Tempfile into String)

**URL:** <https://www.ruby-forum.com/t/file-upload-error-cant-convert-tempfile-into-string/185792>\
**Category:** Rails\
**Created:** [March 26, 2010, 4:47am UTC](https://www.ruby-forum.com/t/file-upload-error-cant-convert-tempfile-into-string/185792 "2010-03-26T04:47:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [March 26, 2010, 4:47am UTC](https://www.ruby-forum.com/t/file-upload-error-cant-convert-tempfile-into-string/185792/1 "2010-03-26T04:47:36Z")

</div>

i tried a method to implementa file uploader by using amethod below

this is ma controlller method to upload

def save\_imports  
Contactslist.save(params[:list])  
render :text =\> “File uploaded successfully”

this is ma view file

.remote

- form\_for(@list, :url=\> save\_imports\_list\_path(@list, :format =\>  
“js”), :html =\> { :multipart =\> true, :target =\> “uploading”, :onsubmit  
=\> “$('list\_submit).disabled = true” }) do |f|  
= link\_to\_close edit\_list\_path(@list)  
.section  
%small  
#{t :add\_contacts\_from\_file}  
%table{ :width =\> 500, :cellpadding =\> 0, :cellspacing =\> 0 }  
%tr  
%td{ :valign =\> :top }  
.label.top.req #{t :upload\_new}:  
=f.file\_field :uploads, :style =\> “width:240px”

i created amodel contact list and nclude amethod as given below

class Contactslist \< ActiveRecord::Base  
def self.save(upload)  
name = upload[‘uploads’]  
puts name  
directory = “public/avatars”  
# create the file path  
path = File.join(directory, name)  
# write the file  
File.open(path, “wb”) { |f| f.write(upload[‘uploads’].read) }  
end  
end  
when i tried to upload a file its showing errors as

TypeError in ListsController#save\_imports

can’t convert Tempfile into String

can anyone help.is there any fault in this method?actually i wanted  
toupload this files into a table callled contactslists or to move to  
a folder in my application pls provide help

---

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [March 26, 2010, 4:57pm UTC](https://www.ruby-forum.com/t/file-upload-error-cant-convert-tempfile-into-string/185792/2 "2010-03-26T16:57:12Z")

</div>

Hey Tony,

You just need

name = upload[‘uploads’].original\_filename

instead of

name = upload[‘uploads’]

/Lasse

2010/3/26 Tony A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [March 27, 2010, 4:46am UTC](https://www.ruby-forum.com/t/file-upload-error-cant-convert-tempfile-into-string/185792/3 "2010-03-27T04:46:04Z")

</div>

Lasse B. wrote:

> Hey Tony,
> 
> You just need
> 
> name = upload[‘uploads’].original\_filename
> 
> instead of
> 
> name = upload[‘uploads’]
> 
> /Lasse
> 
> 2010/3/26 Tony A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

thanks a lot its working now
