Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #2344

Re: How do I upload an image with Sinatra (like Paperclip)?

From "Bohdan S." <alfuken@gmail.com>
Newsgroups comp.lang.ruby
Subject Re: How do I upload an image with Sinatra (like Paperclip)?
Date 2011-04-05 08:46 -0500
Organization Service de news de lacave.net
Message-ID <31b9f43603f8960e486d8d23e76a341e@ruby-forum.com> (permalink)
References <58918166c2dd4b1c91f57c303239642a@ruby-forum.com> <d3b25455b5b2d1076a303013db382056@ruby-forum.com> <b83298b5483d4b78a98f51d6ad605ea8@ruby-forum.com> <1a43fb20f6e5a1b903d1bde579fd8f56@ruby-forum.com>

Show all headers | View raw


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 comp.lang.ruby | Previous | Next | Find similar | Unroll thread


Thread

Re: How do I upload an image with Sinatra (like Paperclip)? "Bohdan S." <alfuken@gmail.com> - 2011-04-05 08:46 -0500

csiph-web