我正在尝试使用以下简单代码上传带有节点的文件:
UpdateController.prototype.uploadUpdateFile = function(req, res)
{
var w = fs.createWriteStream(settings.uploadFolder + settings.updateFile);
req.pipe(w);
w.on('finish', function()
{
res.send(JSON.stringify({
status:0,
filename:settings.uploadFolder + settings.updateFile
}));
}, function()
{
res.send(JSON.stringify({
status:1,
message:"error during file upload, operation failed"
}));
});
}
该文件已正确上传,但由于标题(------ WebKitForm ... / octet-stream ....)和页脚(..------ WebKitFormBoundary9gOZjMubs9GivcUQ-- ..)而在原始文件之间切换被添加到内容中。
如何只获取文件内容?
您必须查看客户端请求的标头,以了解客户端如何决定向您发送文件(文件的编码方式)
您可能最终会使用busboy或依赖于它的另一个软件包:https : //www.npmjs.com/package/busboy
这样的程序包将“解码”浏览器发送的数据。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句