Created
January 28, 2011 02:13
-
-
Save lchanmann/799695 to your computer and use it in GitHub Desktop.
sinatra application with file_uploader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rubygems' | |
| require 'haml' | |
| require 'sinatra' | |
| require 'sinatra/flash' | |
| require 'file_uploader' | |
| enable :sessions | |
| get '/' do | |
| haml :index | |
| end | |
| post '/upload' do | |
| FileUploader.create.save(params[:file]) do |path| | |
| flash[:upload] = "#{path} is saved." | |
| end | |
| redirect '/' | |
| end | |
| __END__ | |
| @@ layout | |
| %html | |
| %head | |
| %title File Uploader | |
| %body | |
| = yield | |
| @@ index | |
| %h1 File Uploader | |
| - if flash[:upload] | |
| %div{:style => 'color:green'}= flash[:upload] | |
| %form{:action => '/upload', :method => 'post', :enctype => 'multipart/form-data'} | |
| %label{:for => 'file'} Select file: | |
| %input{:type => 'file', :id => 'file', :name => 'file'} | |
| %input{:type => 'submit', :value => 'Upload'} |
Author
This is strange. Uploads are not complete. I tried with several images and always the last couple of bytes are missing. i.e. in a picture the lower right corner is missing. Is this a problem with the buffered stream? I use sinatra 1.2.1 and thin 1.2.10
Author
Last broken bytes problem is fixed on v0.2.1.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I actually return path of the uploaded file as String not a File object