【发布时间】:2018-03-29 13:15:27
【问题描述】:
我在node.js中使用multer方式上传,这里详细解释https://ciphertrick.com/2015/12/07/file-upload-with-angularjs-and-nodejs/
我正在尝试使用称为 invoiceId 的请求数据传递另一个信息:
Upload.upload({
url: 'http://localhost:4000/api/ubiq/listInvoiceAttachedFiles/attach', //webAPI exposed to upload the file
data: {file: file, invoiceId:invoiceId} //pass file as data, should be user ng-model
}).then(function (resp) { //upload function returns a promise
if (resp.data.error_code === 0) { //validate success
$window.alert('Success ' + resp.config.data.file.name + ' uploaded');
console.log(resp.config.data.file); ....etc
但服务器端的 req.body 为空:
/** API path that will upload the files */
server.post('/api/ubiq/listInvoiceAttachedFiles/attach', function(req, res) {
console.log(req.body);
security.verifyPermission("/api/ubiq/listInvoiceAttachedFiles/attach", req.session.currentUser, true /*isInSession*/).then(function (successInfo) {
if (!successInfo.isAllowed) {
console.log('not allowed');
return res.json(apiHelp.notAllowed());
}
我做错了什么?
【问题讨论】:
-
你应该作为 post 参数而不是文件传递
-
Dipak chavda 你的意思是通过 $http.post?
-
我使用了不同的 multer of diskstorage() 方法,我可以用这种方式发布可能有帮助吗??
-
为什么不呢,提前谢谢
-
如果发现任何困难,请查看并告诉我