Stream formidable uploads into MongoDB GridFS
Formidable streams uploads to the file system by default. If you're using GridFS to store files you'll then need to turn around and copy them off of the file system. Using
gridform removes this burden.
var mongo =var gridform = ;// assuming you've already created a db instance and opened itgridformdb = db;gridformmongo = mongo;// in your http servervar app = http;
npm install gridform
The module exports a function which takes an options object.
var gridform = ;var options = db: db mongo: mongo filename: fn ;var form = ;
filename function is passed the
file.name before streaming to MongoDB providing an opportunity to return a customized filename with a prefix etc.
mongo are required unless you've specified them on
var gridform = ;gridformdb = db;gridformmongo = mongo;var form = ; // all good
The gridform function returns an instance of
formidable.IncomingForm so you can process uploads without changing any code.
This module utilizes the gridfs-stream module which is exposed as
Run the tests with