https://i.sstatic.net/VFMbl.pngsteps to recreate the issue:
I have a Blob object that I am saving as form data through a service. The response I receive has a content-type of application/octet-stream, as shown in the attached image.
What result is expected?
- To be able to download and view the application/octet-stream file as an image on my local machine using appropriate applications
What actually happens?
I can download the file as an image, but when I try to open it, I get an error message saying that the file format is not supported even though it is supposed to be an image with the .png extension.
function add() {
$.ajax({
url: 'https://localhost:3000/upload/sampleImage.png',
type: 'GET',
success: function (data) {
const link = document.createElement('a');
link.style.display = 'none';
link.download = "sample image";
link.href =
'data:' +
'image/png' +
';base64,' +
window.btoa(unescape(encodeURIComponent(data)));
link.click();
},
error: function (request, error) {
alert("Request: " + JSON.stringify(request));
}
});
}
Any suggestions on how to successfully download and preview the file?