Angular 访问从客户端发送到服务器的FormData对象(Express)

Angular 访问从客户端发送到服务器的FormData对象(Express),angular,express,Angular,Express,我正在实施此解决方案以将文件上载到服务器: 我的问题是如何在服务器端POST方法中访问formData项 代码: router.post('/test', function(req, res) { // Access the formData object sent from the client // Do stuff... } 谢谢 使用以下代码:- router.post('/test', function(req, res) {

我正在实施此解决方案以将文件上载到服务器:

我的问题是如何在服务器端POST方法中访问formData项

代码:

    router.post('/test', function(req, res) {
        // Access the formData object sent from the client
        // Do stuff...
    }
谢谢

使用以下代码:-

 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
          }
     });
  });

所有内容都是未定义的,例如files.file:unfinedhave在服务器配置中使用body解析器。还有你打印的文件。