How do I upload an image with Sinatra (like Paperclip)? - Ruby Forum →

      post '/upload' do
        unless params[:file] &&
               (tmpfile = params[:file][:tempfile]) &&
               (name = params[:file][:filename])
          @error = "No file selected"
          return haml(:upload)
        end
        STDERR.puts "Uploading file, original name #{name.inspect}"
        while blk = tmpfile.read(65536)
          # here you would write it to its final location
          STDERR.puts blk.inspect
        end
        "Upload complete"
      end
    
    ---------
      %h1 Upload
    
      %form{:action=>"/upload",:method=>"post",:enctype=>"multipart/form-data"}
        %input{:type=>"file",:name=>"file"}
        %input{:type=>"submit",:value=>"Upload"}

    Know Your Job Desbription →

    My first sinatra app…

    Working with Rails ⋅  GitHub ⋅  Twitter ⋅  Linked In ⋅  Facebook ⋅  Powered by tumblr
    Fork me on GitHub