Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #2344 > unrolled thread
| Started by | "Bohdan S." <alfuken@gmail.com> |
|---|---|
| First post | 2011-04-05 08:46 -0500 |
| Last post | 2011-04-05 08:46 -0500 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.ruby
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: How do I upload an image with Sinatra (like Paperclip)? "Bohdan S." <alfuken@gmail.com> - 2011-04-05 08:46 -0500
| From | "Bohdan S." <alfuken@gmail.com> |
|---|---|
| Date | 2011-04-05 08:46 -0500 |
| Subject | Re: How do I upload an image with Sinatra (like Paperclip)? |
| Message-ID | <31b9f43603f8960e486d8d23e76a341e@ruby-forum.com> |
Brian Candler wrote in post #929342:
> Almaz OM wrote:
>> phanks:
>>
>> post '/upload' do
>> unless params[:file] &&
>> (tmpfile = params[:file][:tempfile]) &&
>> (name = params[:file][:filename])
>> @error = "No file selected"
>> return haml(:upload)
>> end
>> directory = "public/files"
>> path = File.join(directory, name)
>> File.open(path, "wb") { |f| f.write(tmpfile.read) }
>> end
>>
>> so will be better for me :)
>
> OK. Beware that f.write(tmpfile.read) will use as much RAM as the size
> of the attachment. Hence the suggestion to read it in and write it out
> in blocks of, say, 64K.
"f.write(tmpfile.read)"?? Why so complex?...
post '/upload' do
tempfile = params['file'][:tempfile]
filename = params['file'][:filename]
File.copy(tempfile.path, "./files/#{filename}")
redirect '/'
end
http://tumblr.com/xciegm157
--
Posted via http://www.ruby-forum.com/.
Back to top | Article view | comp.lang.ruby
csiph-web