我正在尝试将 png 文件下载到作为文件输出流的计算机。我正在尝试这段代码:
var userid = this.userid;
let link = null;
function reqListener() {
if (this.responseText !== undefined) {
link = document.createElement("a");
var blob = new Blob([this.responseText], { type: item.type });
link.download = item.name;
link.href = (window.URL || window.webkitURL).createObjectURL(blob);
debugger;
link.click();
}
}
}
它下载文件但无法打开。无法将其加载为 png 时出现错误。它适用于其他类型的文件,但不适用于图像文件。我该如何处理?