I am trying to transfer loading from Formidable directly to Mongo GridFS.
GridStore needs to be opened before any data can be recorded in the time required to open the store, too much data has not been analyzed and it fails.
How can I prepare the GridStore, then handle the incoming download?
function upload (request, response, next, options) { var form = new Formidable.IncomingForm(); var store = new Mongo.GridStore(options.mongoose.connection.db, new ObjectID, 'w+', { root: 'store', chunk_size: 1024 * 64 } ); form.onPart = function (part) { if(!part.filename){ form.handlePart(part); return; } part.on('data', function(buffer){ store.write(buffer); }); part.on('end', function() { store.close(); }); }; store.open( function (error, store) { form.parse(request); }); response.send(); }
Also, the repository instance and repository opening should probably be placed inside onPart somehow.
Alex
source share