文件没有得到保存,而使用multer, MEAN堆栈
file not getting saved while using multer, MEAN stack
我正在构建一个节点应用程序,可以保存使用FormData()发送的文件。我用的是多模块。在FormData中,我使用XPCOM组件发送文件,该组件是FileUtils。
客户端代码
var file = FileUtils.getFile("AChrom", [att.name]);
form.append("file", file);
xhr.send(form); // Object of XMLHTTPRequest
这是我的request.headers
{ host: 'localhost:3000',
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0',
accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'accept-language': 'en-US,en;q=0.5',
'accept-encoding': 'gzip, deflate',
'content-length': '1111',
'content-type': 'multipart/form-data; boundary=---------------------------12849261213577024421216708977',
connection: 'keep-alive' }
这是我的请求。身体
{ messageId: 'xyz@yahoo.com',
subject: 'Testing pdf',
date: '1473703752000000',
author: 'xyz',
mBody: 'welcome to the world of dreamers',
file: '[xpconnect wrapped nsIFile]',
fileName: 'Boot Camp.pdf' }
我在服务器上的代码
var multer = require('multer');
var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, '.')
},
filename: function (req, file, cb) {
cb(null, req.body.fileName)
}
});
var upload = multer({storage: storage});
app.post('/', upload.single('file'), function(req, res) {
console.log(req.body);
res.end("thank you");
})
我在SO上找到了一个类似的帖子,但是我不知道我的代码出了什么问题。
用客户端代码编辑解析
// var file = FileUtils.getFile("AChrom", [att.name]); // this just returns an file object not the actual file
var attachmentFile = new File(path)
form.append("file", file);
xhr.send(form);
相关文章:
- 在自定义mean.io包中使用angular-chart.js作为依赖项
- NodeJS expressJS使用multer和passport将文件上传并保存到MongoDB
- NodeJS Multer is not working
- Express.js和multer:如何知道文件何时全部上传
- 使用MEAN堆栈-查询MongoDB并将值作为变量传递
- 什么是"!函数(){}〃;javascript中的mean/do
- 将数据推送到MongoDB,而无需在MEAN中编辑整个条目
- 事件循环的MEAN.JS setInterval进程(从另一个服务器获取数据)
- NodeJS用Multer上传图片;错误:意外字段“”;
- 什么是“;回归"javascript中的mean
- 与Django和Python相比,Node.js在JavaScript和Express之间的MEAN堆栈中扮演什么角色
- 对于 MEAN 堆栈 docker 容器来说,在 OS X 和 DigitalOcean 上具有相同配置的最简单设置是什
- 无法在MEAN应用程序中路由到部分视图
- 正在创建管理面板Mean.js
- 意外的令牌<当使用MEAN部署到iis服务器时
- 什么's二“"javascript中的mean
- MEAN CRUD错误崩溃无法设置标头
- 无法在MEAN堆栈中传递更多参数
- Highcharts为BoxPlot图表添加了一条Mean线
- 文件没有得到保存,而使用multer, MEAN堆栈