return new Promise((resolve) => {
return fetch('http:\\localhost:8080\downloadzipurl', {
method: 'POST',
headers: {
Authorization: authKey,
'Content-Type': 'application/json',
'cache-control': 'no-cache',
'Access-Control-Allow-Origin': '*',
},
body: JSON.stringify({
userName,
providerId,
sfgFEVersion,
}),
})
.then((resp) => {
if (resp.status >= 200 && resp.status < 300) {
const reader = resp.body.getReader();
const pump = () => reader.read().then((value, done) => {
if (done) {
//writer.close();
console.log('Api returned null response');
} else {
console.log(value);
const blob = new Blob([value], { type: 'application/zip'});
const fileName = 'QCPReport.zip';
FileSaver.saveAs(blob, fileName);
}
});
In above code am getting a response in octet-stream format am reading this stream reader.read().then((value, done)
like this. in value i have Uint8Array. how can I save this value as a zip file?