Kal*_*hir 6 javascript jquery zip blob reactjs
我正在发送从服务器下载 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?
Run Code Online (Sandbox Code Playgroud)
在反应中,我写了下面的函数来下载 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));
},
Run Code Online (Sandbox Code Playgroud)
我正在使用 Blob 并将其类型作为“应用程序/zip”传递。在提取 zip 文件夹时,它抛出了我的错误。
我认为这是标题的问题。需要在请求头中添加以下内容,
{
"content-type": "application/zip",
responseType: "blob",
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2393 次 |
| 最近记录: |