Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 如何使用AJAX post请求下载express js中的文件_Angularjs_Node.js_Express - Fatal编程技术网

Angularjs 如何使用AJAX post请求下载express js中的文件

Angularjs 如何使用AJAX post请求下载express js中的文件,angularjs,node.js,express,Angularjs,Node.js,Express,如何从express js下载文件我在服务器端尝试的是: router.post('/download',function(req,res){ var file = __dirname + '/'+req.body.path; console.log(file); res.download(file); // Set disposition and send it. }); 我得到了我的文件作为回应,如何从另一个角度下载它 router.get('/downlo

如何从express js下载文件我在服务器端尝试的是:

router.post('/download',function(req,res){    
    var file = __dirname + '/'+req.body.path;
    console.log(file);
    res.download(file); // Set disposition and send it.
});
我得到了我的文件作为回应,如何从另一个角度下载它

router.get('/download:file',function(req,res){    
var file = __dirname + '/'+req.params.file;
res.download(file);
});


<a ng-href="/download/{{Filename}}" target="_blank">Download
</a>
路由器.get('/download:file',函数(req,res){ var file=_dirname+'/'+req.params.file; res.download(文件); }); 另一种方法

router.get('/download:file',function(req,res){    
var file = __dirname + '/'+req.params.file;
res.download(file);
});


<a ng-href="/download/{{Filename}}" target="_blank">Download
</a>
路由器.get('/download:file',函数(req,res){ var file=_dirname+'/'+req.params.file; res.download(文件); });
提供目录结构我非常确定文件必须位于面向公众的目录中
res.download('path/to/public/file/on/your/server')
因此您可能希望将文件写入公共目录。请看“/home/Desktop/KRA-GIT/public/uploads/vss830/1478062963587 mongo.jpg”是路径,现在我得到了相应的文件,放在这里,看看你的路径是否正确,由changin在HTMLprovide你的目录结构中解决。我非常确定该文件必须位于面向公众的目录中
res.download('path/to/public/file/on/your/server')
因此您可能希望将文件写入公共目录。请看“/home/Desktop/KRA-GIT/public/uploads/vss830/1478062963587 mongo.jpg”是路径,现在我得到了响应中的文件,在这里看看你的路径是否由changin在HTMLW中正确解决。这对一个文件有效,然后浏览器可以渲染,例如图像或文本文件吗?这对一个文件有效,然后浏览器可以渲染,例如图像或文本文件?