# Problem uploading files

**URL:** <https://www.ruby-forum.com/t/problem-uploading-files/60825>\
**Category:** Rails\
**Created:** [May 17, 2006, 8:33pm UTC](https://www.ruby-forum.com/t/problem-uploading-files/60825 "2006-05-17T20:33:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![agnathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@agnathan](https://www.ruby-forum.com/u/agnathan)\
**Post date:** [May 17, 2006, 8:33pm UTC](https://www.ruby-forum.com/t/problem-uploading-files/60825/1 "2006-05-17T20:33:00Z")

</div>

Hi everyone,

I’m having trouble uploading some files. I’ve set up a simple action  
whose  
view looks like:

\<%= start\_form\_tag({:action =\> ‘handle\_file\_test’}, {:multipart =\>  
true}) %\>  
File to Upload \<%= file\_field\_tag “file” %\>  
\<%= submit\_tag %\>  
\<%= end\_form\_tag %\>

\<% if defined? @file.original\_filename %\>  
\<%= debug @file %\>  
  
\<%= @file.original\_filename %\>  
  
\<%= @file.path %\>  
  
\<%= @file.content\_type %\>  
  
\<% end %\>

The controller simply assigns params[:file] to @file.

For some of my files, “debug @file” reports that @file is a string. For  
these files, @file.path is empty. I can’t figure out any pattern for  
why  
this is happening. I upload one jpeg file, and the file shows up as a  
file.  
I upload another, and the file shows up as a string.

Any ideas?

Thanks!

---

<div class="post-metadata">

**Author:** ![agnathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@agnathan](https://www.ruby-forum.com/u/agnathan)\
**Post date:** [May 17, 2006, 10:58pm UTC](https://www.ruby-forum.com/t/problem-uploading-files/60825/2 "2006-05-17T22:58:57Z")

</div>

Daniel H. wrote:

> For some of my files, “debug @file” reports that @file is a string. For  
> these files, @file.path is empty. I can’t figure out any pattern for  
> why  
> this is happening. I upload one jpeg file, and the file shows up as a  
> file.  
> I upload another, and the file shows up as a string.
> 
> Any ideas?

For uploads below a certain size (I forget how large, maybe a couple of  
k), you get back an IO object that can be read like a file, but is  
actually a string.

I use somthing like:

```
path = uploaded_file.local_path
if path.blank?
    # it's an IOString
else
    # it's a temp file
end

```

when I need to know the difference.

–Al Evans

---

<div class="post-metadata">

**Author:** ![agnathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@agnathan](https://www.ruby-forum.com/u/agnathan)\
**Post date:** [May 17, 2006, 11:40pm UTC](https://www.ruby-forum.com/t/problem-uploading-files/60825/3 "2006-05-17T23:40:59Z")

</div>

Great, thank you!
