From: "Bohdan S." Newsgroups: comp.lang.ruby Subject: Re: How do I upload an image with Sinatra (like Paperclip)? Date: Tue, 5 Apr 2011 08:46:53 -0500 Organization: Service de news de lacave.net Lines: 36 Message-ID: <31b9f43603f8960e486d8d23e76a341e@ruby-forum.com> References: <58918166c2dd4b1c91f57c303239642a@ruby-forum.com> <1a43fb20f6e5a1b903d1bde579fd8f56@ruby-forum.com> NNTP-Posting-Host: bristol.highgroove.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: talisker.lacave.net 1302011429 35437 65.111.164.187 (5 Apr 2011 13:50:29 GMT) X-Complaints-To: abuse@lacave.net NNTP-Posting-Date: Tue, 5 Apr 2011 13:50:29 +0000 (UTC) In-Reply-To: <1a43fb20f6e5a1b903d1bde579fd8f56@ruby-forum.com> X-Received-From: This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway X-Mail-Count: 381003 X-Ml-Name: ruby-talk X-Rubymirror: Yes X-Ruby-Talk: <31b9f43603f8960e486d8d23e76a341e@ruby-forum.com> Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.stben.net!talisker.lacave.net!lacave.net!not-for-mail Xref: x330-a1.tempe.blueboxinc.net comp.lang.ruby:2344 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/.