将文件从AngularJS上传到ExpressJS 4 API

我的AngularJS应用程序通过内部API与Express进行通信。

我在Angular中使用ng-file-upload来处理上传的文件。 上传代码看起来像这样:

Upload.upload({ url: '/api/uploadCSV/', file: CSVfile }).progress(function (evt) { var progressPercentage = parseInt(100.0 * evt.loaded / evt.total); console.log('progress: ' + progressPercentage + '% ' + evt.config.file.name); }).success(function (data, status, headers, config) { console.log('file ' + config.file.name + 'uploaded. Response: ' + data); }).error(function (data, status, headers, config) { console.log('error status: ' + status); }) 

在我的Express app.js ,我设置了这样的API:

  app.post('/api/uploadCSV/', api.uploadCSV); 

在我的实际API代码中,我想要做一些事情:

  exports.uploadCSV = function(req, res){ var csv = req.body.CSVfile; // or something similar // and then code to parse the CSV file and save information from it to MongoDB } 

我可以看到有关如何上传文件并将其存储到服务器的一些示例,但这不是我想要做的; 我只需要将文件发送到我的服务器来读取和parsing。

这是可能的快递,如果是的话,我该如何设置?

编辑:或者也许我应该阅读用户的浏览器中的文件,parsing成Angular JSON和发送到我的服务器的JSON对象?