I am using this function to download the image I am getting from server on frontend of my app.
const downloadImage = () => {
fetch(`url`, {
method: 'GET',
headers: {
'Content-Type': 'image/png',
'Content-Disposition': 'attachment',
},
})
.then((response) => response.blob())
.then((blob) => {
// Create blob link to download
const url = window.URL.createObjectURL(
new Blob([blob]),
);
const link = document.createElement('a');
link.href = url;
link.setAttribute(
'download',
`FileName.png`,
);
document.body.appendChild(link);
link.click();
link.parentNode.removeChild(link);
});
}
its successfully downloading the image but when opening its showing image type not supported