Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Rack Upload handler with Nginx Upload Module support
Ruby
branch: master
Failed to load latest commit information.
lib/rack Fix typo, thanks BrianTheCoder
spec rack-uploads now scans for uploads on all post requests
.document
.gitignore Initial commit to rack-uploads.
LICENSE Initial commit to rack-uploads.
README.rdoc rack-uploads now scans for uploads on all post requests
Rakefile gemspec
VERSION Version bump to 0.2.1
init.rb preparing for first release
rack-uploads.gemspec Bump version number in gemspec too

README.rdoc

rack-uploads

rack-uploads is a middleware which receives uploads and stores them in in the Rack env for easy access.

It works with normal HTTP file uploads, as well as with the Nginx Upload Module.

All multipart params get replaced by a Rack::Uploads::UploadedFile, while still retaining access to the original parameter value.

Dependencies

Development dependencies:

  • rspec

  • rack-test

Usage

Sinatra

use Rack::Uploads

post "/uploads" do
  env['rack.uploads'].each do |upload|
    upload.mv('/some/path/#{upload.filename}')
  end
end

Rails

# config/environment.rb
config.middleware.use "Rack::Uploads"

# app/controller/uploads_controller.rb
class UploadsController < ApplicationController
  def create
    request['rack.uploads'].each do |upload|
      upload.mv("#{RAILS_ROOT}/public/uploads/#{upload.filename}")
    end
  end
end

Options

There are a few options you can pass to rack-uploads during initializiation:

:session_authorized => lambda { |req| req.params['secret'] == "sekrit" } - Only allow uploads with the parameter “secret” set to “sekrit”

:nginx => [{ :tmp_path => "_tmp_path", :filename => "_file_name" }] - Sets the suffixes of the nginx upload parameters

Copyright

Copyright © 2009 Mutwin Kraus. See LICENSE for details.

Something went wrong with that request. Please try again.