Вы можете использовать GridFS внутри метеора, не касаясь дополнительных пакетов.
var db = MongoInternals.defaultRemoteCollectionDriver().mongo.db; //grab the database object
var GridStore = MongoInternals.NpmModule.GridStore;
WebApp.connectHandlers.use('/someurl', function(req, res) {
var bigFile = new GridStore(db, 'bigfile.iso', 'r') //to read
bigFile.open(function(error, result) {
if (error) return
bigFile.stream(); //stream the file
bigFile.on('error', function(e) {...}) //handle error etc
bigFile.on('end', function() {bigFile.close();}); //close the file when done
bigFile.pipe(res); //pipe the file to res
});
});
Однако текущий GridStore/mongo (v1.3.x), используемый Meteor, немного устарел, самая новая версия — 2.x из http://mongodb.github.io/node-mongodb-native/2.0/api-docs/ Похоже, v1.x плохо работает, поэтому вам может понадобиться использовать более новую версию
Второй вариант
var db = MongoInternals.defaultRemoteCollectionDriver().mongo.db; //grab the database object
var GridStore = Npm.require('mongodb').GridStore; //add Npm.depends({mongodb:'2.0.13'}) in your package.js
WebApp.connectHandlers.use('/someurl', function(req, res) {
var bigFile = new GridStore(db, 'bigfile.iso', 'r').stream(true); //the new API doens't require bigFile.open() and will close automatically on end
bigFile.on('error', function(e) {...}); //handle error etc
bigFile.on('end', function() {...});
bigFile.pipe(res); //pipe the file to res
});
В этом примере я использую WebApp.connectHandlers, но вы, конечно, можете использовать железо: роутер или что-то в этом роде. Я попробовал с файлом размером 500 МБ, и все идет хорошо. Вам также необходимо установить res.writeHead(200) и другие вещи, такие как тип содержимого и т.д.
13.01.2015