
Security News
CISA’s 2025 SBOM Guidance Adds Hashes, Licenses, Tool Metadata, and Context
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
If you want to use this because you are performing HTML5 file uploads, you may be doing it the "old way".
There is a "new", better way of doing this. It may be a better solution for your problems.
However, if this is not the case, please read on. I hope you find this middleware useful.
Rack::RawUpload converts raw uploads into normal multipart requests, like those in a form. Rack applications can then read these as normal (using params
for example), rather than from env['rack.input']
or similar.
Rack::RawUpload performs this conversion when all these conditions are met:
application/x-www-form-urlencoded
multipart/form-data
The simpler case. Add these lines in your config.ru
, where appropriate:
require 'rack/raw_upload'
use Rack::RawUpload
If you want to limit the conversion to a few known paths, do:
require 'rack/raw_upload'
use Rack::RawUpload, :paths => ['/upload/path', '/alternative/path.*']
You can also make it so that the conversion only happens when explicitly required by the client using a header. This would be X-File-Upload: true
to make the conversion regardless of the content type. A value of X-File-Upload: smart
would ask for the normal detection to be performed. For this, use the following setting:
use Rack::RawUpload, :explicit => true
Add this to your Gemfile
gem 'rack-raw-upload'
and then add the middleware in application.rb
config.middleware.use 'Rack::RawUpload'
The upload is made into a request argument called file
. In several popular frameworks, this can be accessed as params[:file]
. This includes Rails and Sinatra, but may be different in other frameworks.
Raw uploads, due to their own nature, can't provide additional arguments in the request. This limitation can be worked around using headers.
X-File-Name
: specify the name of the uploaded file.X-File-Upload
: explicitly tells whether to perform the conversion or not. Possible values are 'true' (string), 'false' (string) or 'smart'. Default is 'smart', unless the middleware is initialized with :explicit => true
, in which case default is 'false'.X-Params
: query string with additional arguments. On Rails or Sinatra, you can read these as params[:name_of_argument]
.X-JSON-Params
: same thing, but in the form of a JSON string.X-Query-Params
: deprecated. Equivalent to X-JSON-Params
. Will be removed in future versions.A blog post on Ajax uploads. These are raw uploads and can be greatly simplified with this middleware:
This middleware should work with Ruby 1.8.7, 1.9.2, 1.9.3, REE, Rubinius and JRuby. Tests for all these platforms are run on the wonderful Travis-CI regularly, and the current status of these is:
FAQs
Unknown package
We found that rack-raw-upload demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.
Security News
ESLint now supports parallel linting with a new --concurrency flag, delivering major speed gains and closing a 10-year-old feature request.