Bitbucket is a code hosting site with unlimited public and private repositories. We're also free for small teams!

Close
This is an Apache 2.2+ module that supports serving files from MongoDB GridFS.

See http://www.mongodb.org/ and http://www.mongodb.org/display/DOCS/GridFS for more information.

See LICENSE file for licensing details.

Availability:
This code is available free of charge from https://bitbucket.org/onyxmaster/mod_gridfs/.
Old driver that is written in C and used MongoDB C driver is still available in the "c-driver" branch.

Building (see next section for Ubuntu fast-forward instructions):
Make sure you have g++ and boost libraries (filesystem, system, thread) installed
Install Apache 2.2+ and APXS
Grab the module from https://bitbucket.org/onyxmaster/mod_gridfs/, remember the absolute path to the directory (referenced as /path/to/mod_gridfs later on)
Grab MongoDB from https://github.com/mongodb/mongo (post-2.0 branch required) and go to its directory
Build MongoDB C++ driver source package from MongoDB sources:
	scons distclient
Unpack the resulting archive (mongo-cxx-driver.tgz) and go it its directory
Fix the driver build environment (build static library with PIC to allow module to be built as a shared library):
	echo 'env.Append(CCFLAGS="-fPIC")' >> SConstruct
Apply the GridFS slaveOk patch:
	patch -d src/mongo/client < /path/to/mod_gridfs/patches/gridfs-slaveok
Build the driver:
	scons

Ubuntu pre-build instructions:
sudo apt-get -y install wget g++ apache2 apache2-threaded-dev libboost-filesystem-dev libboost-system-dev libboost-thread-dev

Ubuntu build instructions:
wget --no-check-certificate https://bitbucket.org/onyxmaster/mod_gridfs/get/release.tar.gz
tar xzf release.tar.gz
rm release.tar.gz
mv onyxmaster-mod_gridfs-* mod_gridfs
cd mod_gridfs
wget --no-check-certificate https://github.com/mongodb/mongo/tarball/master
tar xzf master
rm master
mv mongodb-mongo-* mongo
scons -C mongo distclient
tar xzf mongo/mongo-cxx-driver.tgz
rm -rf mongo
echo 'env.Append(CCFLAGS="-fPIC")' >> mongo-cxx-driver/SConstruct
patch -d mongo-cxx-driver/src/mongo/client < patches/gridfs-slaveok
scons -C mongo-cxx-driver
make -C gridfs

Ubuntu pre-installation instructions:
sudo apt-get -y install apache2 libstdc++6 libboost-filesystem libboost-system libboost-thread

Ubuntu installation instructions (copy mod_gridfs directory to a target machine first):
cd mod_gridfs
sudo make -C gridfs install

Configuration:
GridFSConnection -- Connection string ("host[:port]" for single hosts, "replicaSetName/host[:port],[host[:port], ...]" for replica sets)
GridFSDatabase <database> -- Set database name
GridFSCacheMaxAge <maxAge> -- Optional, set cache max age in seconds (default is 1 week, maximum is 10 years), set to 0 to disable expiration caching (see Notes below)
GridFSConnectTimeout <timeout> -- Optional, set MongoDB connection timeout in seconds (default is 5 seconds)
GridFSSlaveOk <On|Off> -- Optional, set MongoDB slaveOk mode (horizontal sharding)

Configuration example:
GridFSConnection rsTest/db1,db2
GridFSDatabase my_database

Implementation notes:
This module was developed to serve static content that is cached on frontend reverse proxies, hence by default it sets the following headers:
	Cache-Control: public, max-age=<max_age>
	Expires: <Date+max_age>
	Last-Modified: <uploadDate>
	Etag: <md5> (if MD5 is available for file)
You can disable "Cache-Control" and "Expires" headers by setting GridFSCacheMaxAge to 0.

Content-type, if not specified in GridFS file "contentType" field, is automatically determined using mod_mime (or any other type checker module that works without accessing file contents).
Also, it supports HEAD requests, conditional queries (If-Modified-Since and/or If-None-Match with proper 304 Not Modified response).
It doesn't support range queries (not going to be implemented soon).

Known problems:
If you're using gcc version less than 4.5, Apache parent process would crash when reloading modules (on a restart after module list is updated).
This is a known problem with gcc and libstdc++. Unfortunately, the only workaround is to upgrade your compiler and standard C++ library.

Recent activity

rado_h

Commits by rado_h were pushed to rado_h/mod_gridfs

4c22a26 - Change error status code on authentication failure
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.