Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Rack Upload handler with Nginx Upload Module support
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib/rack
spec
.document
.gitignore
LICENSE
README.rdoc rack-uploads now scans for uploads on all post requests
Rakefile
VERSION
init.rb preparing for first release
rack-uploads.gemspec

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.