【发布时间】:2023-03-03 23:00:01
【问题描述】:
我正在从我的客户端 javascript 将一个 csv 文件作为 Post 请求上传到我的节点服务器。我也能够处理 nodejs 服务器上的请求。请帮助我获取文件并在服务器端解析文件。该文件将是一个 csv 文件,我需要解析该文件并读取该文件的内容。
我附上客户端上传文件的源代码sn-p以及下面的服务器端供参考。
myAngularApp.service('fileUpload', ['$http', function ($http) {
this.uploadFileToUrl = function(file, uploadUrl){
var fd = new FormData();
fd.append('file', file);
$http.post(uploadUrl, fd, {
transformRequest: angular.identity,
headers: {'Content-Type': undefined}
})
.success(function(){
// handling on success data
})
.error(function(){
// handling on error data
});
}
在 NodeJs 服务器上:
router.post('/filter-reports', function(req, res) {
console.log('Came inside the Node js router.. Now.. its all up to me to format the data....');
console.log(req);
});
【问题讨论】:
-
Node/Express file upload 的可能重复项
-
你提供的信息很少。所以你能在 req.body 和 req.files 上做一个 console.log 看看文件在哪里吗。我问这个是因为 express.4.0+ 我们不能使用 bodyparser 处理多格式数据。
标签: javascript node.js node.js-connect node.js-domains