dafydd
(dafydd)
January 1, 2007, 8:03pm
1
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~
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
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 Zygmuntowicz-- Lead Rails Evangelist
-- ez@engineyard.com
-- Engine Yard, Serious Rails Hosting
-- (866) 518-YARD (9273)
dafydd
(dafydd)
January 1, 2007, 9:36pm
3
Yow!
Thanks, Ezra.
You Rails folks are exceptionally patient and helpful with newbies.
cheers
dafydd