Rack middleware to handle raw file uploads
Ruby
Switch branches/tags
Nothing to show
Pull request Compare This branch is 75 commits behind New-Bamboo:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib/rack
test
Gemfile
LICENSE
README.md
Rakefile
VERSION
rack-raw-upload.gemspec

README.md

Rack Raw Upload middleware

Rack::RawUpload converts files uploaded with mimetype application/octet-stream into normal form input, so Rack applications can read these as normal, rather than as raw input.

Assumptions

Rack::RawUpload expects that requests will:

  1. be POST requests
  2. set the mimetype application/octet-stream

Configuration

The simpler case:

use Rack::RawUpload

If you want to limit the conversion to a few known paths, do:

use Rack::RawUpload, :paths => ['/upload/path', '/alternative/path.*']

More options

Specifying the file name of the upload

Raw uploads, due to their own nature, don't include the name of the file being uploaded. You can work around this limitation by specifying the filename as an HTTP header.

When present, Rack::RawUpload will assume that the header X-File-Name will contain the filename.

Additional query parameters

Again, the nature of raw uploads prevents us from sending additional parameters along with the file. As a workaround, you can specify there as a header too. They will be made available as normal parameters.

When present, Rack::RawUpload will assume that the header X-Query-Params contains these additional parameters. The values are expected to be in the form of a JSON hash.

Additional info

A blog post on HTML5 uploads, which are raw uploads, and can be greatly simplified with this middleware: