Creating zip file download from an ascii response fails to open due to unsupported format. In postman I can confirm that when making my get request and saving the file for this exact same request the zip behaves correctly. So, I'm assuming that this is an error in my code.
The response includes both a content-type (application/zip) and content-disposition (attachment; filename=exampleFileName.ascii.zip). Here is my attempt:
.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);
Any suggestions would be helpful. Thanks in advance
question from:
https://stackoverflow.com/questions/65944456/creating-zip-file-download-from-an-ascii-response-fails-to-open-due-to-unsupport 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…