Skip to content

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

License

Notifications You must be signed in to change notification settings

mattbeedle/rack-gridfs

This branch is 9 commits ahead of, 58 commits behind skinandbones/rack-gridfs:master.

Folders and files

NameName
Last commit message
Last commit date
Sep 21, 2009
Sep 26, 2010
Apr 21, 2010
Sep 22, 2009
Sep 21, 2009
Sep 26, 2010
Sep 26, 2010
Oct 11, 2009
Sep 26, 2010

Repository files navigation

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 supply an id for looking up the file in the GridFS store.

For example,

GET '/gridfs/someobjectid'

If the prefix is “gridfs”, then the id will be be “someobjectid”.

Mongo Driver Compatibility Notes

This version is currently based off of mongo-0.20.1.

As of mongo-0.19.1, there have been significant changes to GridFS. I do not plan to support versions of the mongo driver prior to 0.19. There are some compatibility issues with mongo-0.19 vs. mongo-0.20 (Mongo::ObjectId vs. BSON::ObjectId). For now, I am choosing to support mongo-0.20.

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’.

Sinatra Example

# TODO: THIS COULD USE A LOT MORE EXPLANATION!

require 'rubygems'
require 'sinatra'

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

get /.*/ do
  "The URL did not match a file in GridFS."
end

Copyright © 2010 Blake Carlson. See LICENSE for details.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%