Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Rack middleware for Mongo GridFileSystem
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


This is intended to be a simple Rack middleware for hosting site assets in a MongoDB GridFileSystem. Right now it assumes you're using Mongoid, mostly as a simple way to avoid needing any custom connection-management code

Unlike most similar tools, this is doing the lookup on the raw file path itself (optionally customized by passing a block to the initializer), not using a BSON ObjectID. The intended use-case for is storing site assets in GridFS directly and accessing them with normal human-friendly URLs, just like if they were sitting on your hard drive

It's sending a file handler not the raw data, so this should be low-memory use even for large files. It will set Etag and Last-Modified headers, and respond with a 304 Not Modified when possible. Any additional caching you should do yourself where appropriate


# Gemfile
gem 'grifizoid', :git => 'git://'

and bundle install

Use with Rails 3

# application.rb
config.middleware.use Rack::GridFS do |req|
  site      = Site.where(:host =>

  File.join(site.to_param, req.path_info)

Now someone going to will result in the middleware doing a query to find the site '' (with an ID like 4d80c69f4cfad13cd100000c) and then looks for a GridFS file named 4d80c69f4cfad13cd100000c/file.jpg, sending it through to the client if found or else passing the request through to your app

Some ideas/code taken from:

Something went wrong with that request. Please try again.