# Small file upload

**URL:** <https://www.ruby-forum.com/t/small-file-upload/80909>\
**Category:** Rails\
**Created:** [January 1, 2007, 9:06pm UTC](https://www.ruby-forum.com/t/small-file-upload/80909 "2007-01-01T21:06:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dafydd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8491ac/32.png) [@dafydd](https://www.ruby-forum.com/u/dafydd)\
**Post date:** [January 1, 2007, 9:06pm UTC](https://www.ruby-forum.com/t/small-file-upload/80909/1 "2007-01-01T21:06:00Z")

</div>

Hi folks

Searching the list, I notice this problem was introduced a while back  
but there was no reply. Anyhow, I’m now finding myself up against it:

I’m trying to upload zip files and unzip them into a directory using  
rails. It works fine with larger files; here’s the data at the  
breakpoint:

irb(#UploadController:0x2262a84):001:0\> params  
=\> {“commit”=\>“Upload”, “action”=\>“save\_file”, “controller”=\>“upload”,  
“site”=\>{“name”=\>“dh”, “zip\_file”=\>#\<File:/tmp/CGI805.1\>}}

However, with a smaller file (not just with zip files, actually) i get  
the following:

irb(#UploadController:0x24ad6a4):001:0\> params  
=\> {“commit”=\>“Upload”, “action”=\>“save\_file”, “controller”=\>“upload”,  
“site”=\>{“name”=\>“smalltest01”, “zip\_file”=\>#StringIO:0x24e0ce8}}

and the path returns nil.

Does anybody have any insight into this problem? Any help would be  
appreciated.

Thanks

cheers  
dafydd

---

<div class="post-metadata">

**Author:** ![dafydd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8491ac/32.png) [@dafydd](https://www.ruby-forum.com/u/dafydd)\
**Post date:** [January 1, 2007, 10:32pm UTC](https://www.ruby-forum.com/t/small-file-upload/80909/2 "2007-01-01T22:32:07Z")

</div>

Hi~

On Jan 1, 2007, at 12:03 PM, dafydd wrote:

> irb(#UploadController:0x2262a84):001:0\> params  
> and the path returns nil.
> 
> Does anybody have any insight into this problem? Any help would be  
> appreciated.
> 
> Thanks
> 
> cheers  
> dafydd

```
Thats the way rails works. If an uploaded file is less then 10Kb

```

then it will be put in a StringIO, if it is over 10k it will get put  
in a tmpfile. You will have to branch with conditionals on this to  
support what you want. If its a StringIO then you need to read it  
into mem and write it out to wherever you want it. If its a tmpfile  
then you can just call path on it and move it somewhere.

if StringIO === params[:zip\_file]  
data = params[:zip\_file].read  
File.open(‘some/path’, ‘wb’){|f| f.write data }  
else

# its a tmpfile

end

Cheers-  
– Ezra Z.  
– Lead Rails Evangelist  
– removed\_email\_address@domain.invalid  
– Engine Y., Serious Rails Hosting  
– (866) 518-YARD (9273)

---

<div class="post-metadata">

**Author:** ![dafydd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8491ac/32.png) [@dafydd](https://www.ruby-forum.com/u/dafydd)\
**Post date:** [January 1, 2007, 10:38pm UTC](https://www.ruby-forum.com/t/small-file-upload/80909/3 "2007-01-01T22:38:08Z")

</div>

Yow!

Thanks, Ezra.

You Rails folks are exceptionally patient and helpful with newbies.

cheers  
dafydd

---

<div class="post-metadata">

**Author:** ![dafydd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8491ac/32.png) [@dafydd](https://www.ruby-forum.com/u/dafydd)\
**Post date:** [January 1, 2007, 10:48pm UTC](https://www.ruby-forum.com/t/small-file-upload/80909/4 "2007-01-01T22:48:10Z")

</div>

dafydd wrote:

> You Rails folks are exceptionally patient and helpful with newbies.

Because Rails is too.

😉

–  
Phlip  
[Redirecting...](http://www.greencheese.us/ZeekLand) ← NOT a blog!!!

---

<div class="post-metadata">

**Author:** ![dafydd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8491ac/32.png) [@dafydd](https://www.ruby-forum.com/u/dafydd)\
**Post date:** [January 2, 2007, 2:02am UTC](https://www.ruby-forum.com/t/small-file-upload/80909/5 "2007-01-02T02:02:22Z")

</div>

dafydd wrote:

> You Rails folks are exceptionally patient and helpful with newbies.

As long as you aren’t trying to type } in irb on a non-English keyboard!  
Then we bite you with large teeth.

😕

rluv
