MongoDB has a very nice feature called GridFS, which removes the need to store binary data in the filesystem. This example will feature a small (and completely unstyled) image gallery. The gallery allows you to upload a file and store it into MongoDB.
You can find the source code of this example in the chapter3/mongodb-image
directory.
You should have installed the Morphia module in your application and should have a configured up-and-running MongoDB instance.
The application.conf
file should feature a complete MongoDB configuration as for any Morphia-enabled application. Furthermore, a special parameter has been introduced, which represents the collection to store the binary data. The parameter is optional anyway. The uploads
collection resembles the default.
morphia.db.host=localhost morphia.db.port=27017 morphia.db.name=images morphia.db.collection.upload=uploads
The routes file features four routes. One shows the index page...