我正在将带有文件和字段的 FormData 发送到我的服务器上的路由,但无法让 connect-busboy 触发这两个事件。
在客户端,我有:
var data = new FormData();
data.append('file', MyFile);
data.append('key_one', 'value_one');
我正在使用 fetch,因此我将数据分配给 fetch 对象的 body 属性。
fetch(url, {
method: 'POST',
body: data
}).then(...){...}.catch(...){...}
在服务器 url 路由上:
我使用配置有的 busboy 中间件
limits: {fileSize: 5 * 1024 * 1024, parts: 2}
然后我有,
req.pipe(req.busboy);
req.busboy.on('field', function(key, value){
console.log('field fired');
}
req.busboy.on('file', function(fieldname, file, filename){
console.log('file fired');
}
我的问题是我只得到'文件被解雇'。如果我取出文件侦听器,那么我将被“解雇”。有谁知道为什么只有文件被这个设置触发?此外,我现在使用的唯一其他中间件是cookieParser
,expressSession
和护照。