【发布时间】:2019-09-06 13:57:53
【问题描述】:
我的应用是用mean 创建的,我也是 docker 的用户。我的应用程序的目的是创建和下载 CSV 文件。我已经创建了我的文件,将其压缩并放在一个临时文件夹中(下载后该文件将被删除)。这部分在 nodejs 服务器端,可以正常工作。
我已经使用了一些东西,比如 (res.download),它应该直接在浏览器中下载文件,但没有附加任何内容。我尝试在 angularjs 部分使用 blob,但它不起作用。
getData 函数创建并压缩文件(它存在,当我查看应用程序的保存位置时可以直接访问它)。
exports.getData = function getData(req, res, next){
var listRequest = req.body.params.listURL;
var stringTags = req.body.params.tagString;
//The name of the compressed CSV file
var nameFile = req.body.params.fileName;
var query = url.parse(req.url, true).query;
//The function which create the file
ApollineData.getData(listRequest, stringTags, nameFile)
.then(function (response){
var filePath = '/opt/mean.js/modules/apolline/client/CSVDownload/'+response;
const file = fs.createReadStream(filePath);
res.download(filePath, response);
})
.catch(function (response){
console.log(response);
});
};
我的主要问题是直接在浏览器中下载这个文件而不使用任何变量,因为它可能很大(比如几个 GB)。我想下载它然后删除它。
【问题讨论】:
标签: javascript node.js angularjs mean-stack