sinatra.rb upload image


/ Published in: Rails
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.