在您将文件附加到我相信的 formData-object 之后,无法检索这些文件。
您必须将 formData-object 发送到某个地方,然后从 req-object 或类似的东西中获取文件。
就我而言(angularJS + nodeJS),我从 SO 上的答案(链接如下)中对此进行了测试:
角度:
var fd = new FormData();
fd.append('file', file);
$http({
method:"POST",
url:"uploadFile",
data: fd,
withCredentials: true,
headers: {'Content-Type': undefined },
transformRequest: angular.identity
});
节点(expressJS):
app.post('/uploadFile', function(req,res){
fs.readFile(req.files.file.path, function(err, data){
// Do something with the data (which holds the file information)
});
});
要查看您可以对文件执行哪些操作,请阅读以下内容:
http://nodejs.org/api/fs.html
代码取自:
AngularJS: how to implement a simple file upload with multipart form?