I am working on a project where my project mate is sending me a JSON file in a API response like this-
DateCreation : "24/02/2023 08:25" DeathCertificate : "b'/9j/4AAQSkZJRgABAQEASABIAAD/7QA4UGhvdG9zaG9wIDM DeathCertificateN : "xn6n2j7h.jpg" IdExecutorN : "tmmz61dl.png" IdExecutorP : "b'iVBORw0KGgoAAAANSUhEUgAAAoAAAAHgCAMAAAF1CBxAAAA IdRequest : 49
She is using Python to encode the file to binary and then base64 with these code-
file = open(os.path.join(UPLOADS_PATH,"Request", requestData[0][1]), 'rb')
file_read = file.read()
IdExecutorP = base64.encodebytes(file_read)
I am using this code in my HTTP request in Javascript to get the file:
request.onreadystatechange = () => {
if (request.readyState == 4 && request.status === 200) {
let reqdata = JSON.parse(request.response)
const dcbase64= [reqdata[0].DeathCertificate];
const dcname= reqdata[0].DeathCertificateN;
const exbase64= reqdata[0].IdExecutorP;
const exname= reqdata[0].IdExecutorN;
decoded_file = atob(dcbase64);
blob = new Blob([decoded_file], {type: 'image/png'});
}
};
But I am getting the error- enter image description here
I am not sure where the exact problem is... If anyone can help... that would be great!