我正在使用ng2-file-upload https://valor-software.com/ng2-file-upload/在我的平均值应用(角度6 +节点)中上传图片 该代码在本地运行,但是在服务器中,出现错误:状态响应:422 URL不可处理实体。
节点代码:
....
var path = require('path')
var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, './uploads/')
},
filename: function (req, file, cb) {
cb(null, path.parse(file.originalname).name + path.extname(file.originalname)) //Appending extension
console.log(file.originalname);
}
});
var upload = multer({ storage: storage }).any();
router.post('/upload', function (req, res, next) {
upload(req, res, function (err) {
if (err) {
console.log('here');
// An error occurred when uploading
console.log(err);
return res.status(422).send("an Error occured while uploading")
}
// No error occured.
console.log('no error');
return res.send("Upload Completed "); });
});
如何解决此问题?