我正在实施此解决方案,用于将文件上传到服务器:File Upload with Angular2 to Rest API
我的问题是如何在服务器端POST方法中访问formData项目?
代码:
router.post('/test', function(req, res) {
// Access the formData object sent from the client
// Do stuff...
}
谢谢!
答案 0 :(得分:0)
使用以下代码: -
router.post('/test', function(req, res) {
let formidable = require('formidable');
let form = new formidable.IncomingForm();
form.parse(req, function(err, fields, files) {
// fields will get all fields
if(files.file && files.file.name){
//file your uploaded file
}
});
});