所以我尝试通过axios和blob下载一个文件。问题是我需要传递一个密码,因此我不能使用"GET“请求。出于测试目的,我仍然发出了一个" get“请求来启动。由于项目已经结束,我想最终解决这个问题,但我找不到解决方案。
这是我的工作代码,带有一个"GET“请求来给你一个想法。
axios({
url: `/api/download/?uuid=${uuid}&password=${password}`,
method: "GET",
responseType: "blob",
})
.then((response) => {
var fileURL = window.URL.createObjectURL(
new Blob([response.data])
);
var fileLink = document.createElement("a");
fileLink.href = fileURL;
fileLink.setAttribute("download", filename);
document.body.appendChild(fileLink);
fileLink.click();
self.showLottie = false;
})
.catch(function (error) {
self.showLottie = false;
alert("Download failed");
});发布于 2021-07-08 17:31:42
好的,所以基本上我要做的就是把uuid和密码放在一个params对象中。
axios({
url: `/api/download`,
method: "GET",
responseType: "blob",
params: {
uuid,
password,
},
})
.then((response) => {
var fileURL = window.URL.createObjectURL(
new Blob([response.data])
);
var fileLink = document.createElement("a");
fileLink.href = fileURL;
fileLink.setAttribute("download", filename);
document.body.appendChild(fileLink);
fileLink.click();
self.showLottie = false;
})
.catch(function () {
self.showLottie = false;
alert("Download failed");
});https://stackoverflow.com/questions/68272646
复制相似问题