Posted By

almazom on 07/24/10


Tagged

image ruby upload sinatra


Versions (?)

sinatra.rb upload image


 / Published in: Rails
 

  1. post '/upload' do
  2. unless params[:file] &&
  3. (tmpfile = params[:file][:tempfile]) &&
  4. (name = params[:file][:filename])
  5. @error = "No file selected"
  6. return haml(:upload)
  7. end
  8. directory = "public/files"
  9. path = File.join(directory, name)
  10. File.open(path, "wb") { |f| f.write(tmpfile.read) }
  11. end
  12.  
  13. ----------------
  14. %form{:action=>"/upload",:method=>"post",:enctype=>"multipart/form-data"}
  15. %input{:type=>"file",:name=>"file"}
  16. %input{:type=>"submit",:value=>"Upload"}

Report this snippet  

You need to login to post a comment.