Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 使用busboy解析文件流并在express中直接写入GridFs_Node.js_Express_Multipartform Data_Gridfs_Busboy - Fatal编程技术网

Node.js 使用busboy解析文件流并在express中直接写入GridFs

Node.js 使用busboy解析文件流并在express中直接写入GridFs,node.js,express,multipartform-data,gridfs,busboy,Node.js,Express,Multipartform Data,Gridfs,Busboy,你好 我试图弄清楚如何在express framework中将上传文件直接写入GridFs 我编写了如下代码,问题是文件事件“file”从未发出 :( console.log(req.headers['content-type'])显示了什么?我的意思是,如果你把它放在post()路由处理程序中,它会输出什么?@mscdex console.log(req.headers['content-type'])显示'multipart/form data;boundary=----WebkitForm

你好

我试图弄清楚如何在express framework中将上传文件直接写入GridFs

我编写了如下代码,问题是文件事件“file”从未发出

:(


console.log(req.headers['content-type'])
显示了什么?我的意思是,如果你把它放在
post()路由处理程序中,它会输出什么?@mscdex console.log(req.headers['content-type'])显示'multipart/form data;boundary=----WebkitFormBoundaryTJDADFAF'我弄明白了!太愚蠢了!我需要app.js中的另一个模块multiparty,这导致了一切。
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;