0.01
No commit activity in last 3 years
No release in over 3 years
Rack Upload handler with Nginx Upload Module support
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies
 Project Readme

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 © 2009 Mutwin Kraus. See LICENSE for details.