问题描述
由于格式不受支持,无法打开从 ASCII 响应创建 zip 文件下载。在邮递员中,我可以确认在发出 get 请求并为此完全相同的请求保存文件时,zip 的行为正确。所以,我假设这是我的代码中的错误。
响应包括内容类型(应用程序/zip)和内容配置(附件;文件名=exampleFileName.ascii.zip)。这是我的尝试:
.then(async (response) => {
const convertReq = ['ascii'];
const sliceFileName = response.headers['content-disposition'].indexOf('=') + 1;
const fileName = response.headers['content-disposition'].slice(sliceFileName);
const contentType = response.headers['content-type'];
let raw;
if (convertReq.includes(Object.keys(exportFormats)[0])) {
const buffer = new ArrayBuffer(response.data.length);
raw = new Uint8Array(buffer);
}
const newBlob = new Blob([raw],{ type: contentType });
const url = window.URL.createObjectURL(newBlob);
const link = document.createElement('a');
link.href = url;
link.download = fileName;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
任何建议都会有所帮助。提前致谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)