/rack-gridfs

Rack middleware for adding HTTP endpoints for files stored in MongoDB GridFS

Primary LanguageRubyMIT LicenseMIT

Rack::GridFS

Rack:GridFS is a Rack middleware for creating HTTP endpoints for files stored in MongoDB's GridFS. You can configure a prefix string which will be used to match the path of a request and create a key for looking up the file in the GridFS store.

For example,

GET '/gridfs/images/foo.jpg'

If the prefix is “gridfs”, then the key will be be “images/foo.jpg”.

Dependencies

  • ActiveSupport (activesupport)

  • Mongo Ruby Driver v0.15.1+ (mongo)

Installation

sudo gem install skinandbones-rack-gridfs --source=http://gems.github.com

Usage

require 'rack/gridfs'
use Rack::GridFS, :hostname => 'localhost', :port => 27017, :database => 'test', :prefix => 'gridfs'

You must specify MongoDB database details:

  • hostname: the hostname/IP where the MongoDB server is running. Default 'localhost'.

  • port: the port of the MongoDB server. Default 27017.

  • database: the MongoDB database to connect to.

  • prefix: a string used to match against incoming paths and route to through the middleware. Default 'gridfs'.

Caveats

This is an experimental project. The Ruby GridFS adaptor is still pretty new and the performance is known to be slow. I wouldn't recommend using this middleware for anything high-volume in production.

Sinatra Example

require 'rubygems'
require 'sinatra'

require 'rack/gridfs'
use Rack::GridFS, :hostname => 'localhost', :port => 27017, :database => 'test', :prefix => 'gridfs'

get /.*/ do
  "Whatchya talking about?"
end

Copyright © 2009 Blake Carlson. See LICENSE for details.