Small file upload

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

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
[email protected]
– Engine Y., Serious Rails Hosting
– (866) 518-YARD (9273)

Yow!

Thanks, Ezra.

You Rails folks are exceptionally patient and helpful with newbies.

cheers
dafydd

dafydd wrote:

You Rails folks are exceptionally patient and helpful with newbies.

Because Rails is too.

:wink:


Phlip
Redirecting... ← NOT a blog!!!

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.

:confused:

rluv