:)嗨!
我正在试图弄清楚如何在快速框架中将上传文件直接写入GridF。
我编写了如下代码,问题是文件事件“file”永远不会发出。
:(
var mongoose = require('mongoose');
var express = require('express');
var router = express.Router();
var fs = require('fs');
var Busboy = require('busboy');
router.get('/test', function(req, res){
res.render('test-gridfs', {title: 'TESTING GRIDFS'});
})
router.post('/test', function(req, res){
var busboy = new Busboy({headers: req.headers});
var gfs = req.gfs;
busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
console.log('File [' + fieldname + ']: filename: ' + filename);
file.pipe(gfs.createWriteStream({
filename: 'moon.jpg',
content_type: 'image/jpg'
}))
});
busboy.on('finish', function() {
res.json({result: 'finish'});
});
req.pipe(busboy);
})
module.exports = router;