我正在发送从服务器下载 zip 文件夹的请求,该请求向我发送以下响应 - (Zip 文件夹以字节为单位)
PK�s�H test.txt~���T*-N-R�R*I-.Q���PK�/[�PK�s�Htest.txt���T*-N- R�R*I-.Q���PK�/[�PK�s�H�/[� test.txt~PK�s�H�/[�Ltest.txtPKm�
在 react 中,我编写了以下函数来下载 zip 文件夹。提取 zip 文件夹时出现错误。
downloadUtmFile: function() {
function download(text, name, type) {
var a = document.createElement("a");
var file = new Blob([text], {type: type});
a.href = URL.createObjectURL(file);
a.download = name;
a.click();
}
DashboardStore.downloadFile(API_ENDPOINT.utmFileDownload).then(function(result) {
download(result,'', 'application/zip');
}.bind(this), function(error) {
this.setState({
message: error
});
}.bind(this));
},
我正在使用 Blob 并将其类型传递为“application/zip”
提取 zip 文件夹时,它会抛出错误。
最佳答案
我认为这是标题的问题。需要在请求头中添加以下内容,
{
"content-type": "application/zip",
responseType: "blob",
}
关于javascript - 在 javascript 中下载带有 REST 请求的 zip 文件夹。 react .js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38118753/