try copying the code directly from postman see what you might be missing.
so this is a good question because working with binary data can be tricky. I haven't done exactly what you are attempting to do but, I have made a laravel page that uploads a spreadsheet processes that changes data then pops up a download of the modified spreadsheet. and working with binary was a complete pain but here is what I learned. First the basic form.
<input id="file" type="file" class="form-control" name="file" style="height:auto;" required />
then the ajax for upload
$.ajax({
async: true,
method: 'POST',
enctype: 'multipart/form-data',
processData: false,
contentType: false,
cache: false,
url: "priceIncrease/parseHeaders",
data: formData,
xhr: function () {
var myXhr = $.ajaxSettings.xhr();
if (myXhr.upload) {
myXhr.upload.addEventListener('progress', progress, false);
}
return myXhr;
}
});
There is extra in here thats handling progress bars but it isnt related to working with binary data so I will just skip it.
Now I parse the file into an array process it and want to return a spreadsheet to the user this is where the binary gigery pokery starts. When I return the data I had to encode it as base64
$fqn = storage_path() . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . $priceIncreaseResult['filepath'] . $priceIncreaseResult['filename'];
$response = base64_encode(file_get_contents($fqn));
Then on the frontend I gave it the mime type and converted back out of base64
if(data['progress']['file']){
var result = data['progress']['file'];
var a = document.createElement("a");
var file = document.getElementById("file");
var filename = file.files[0].name;
console.log(filename);
var blob = new Blob([s2ab(atob(result))], {
type: 'data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,'
});
a.href = URL.createObjectURL(blob);
a.download = filename;
document.body.appendChild(a);
a.click();
a.remove();
}
the final piece here is the type conversion
function s2ab(s) {
var buf = new ArrayBuffer(s.length);
var view = new Uint8Array(buf);
for (var i=0; i!=s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
return buf;
}
I know this isnt a one off answer but, I do hope you get some incite about working with binary data.