Prev: re-organize original text data then write in files
Next: Text extraction from MS Office and PDF
From: Almaz Om on 24 Jul 2010 07:15 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 :) -- Posted via http://www.ruby-forum.com/.
From: Brian Candler on 30 Jul 2010 13:03 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. -- Posted via http://www.ruby-forum.com/.
|
Pages: 1 Prev: re-organize original text data then write in files Next: Text extraction from MS Office and PDF |