#Fetching a PDF file from API
17 messages ยท Page 1 of 1 (latest)
yea, that was an error on my part (i tried different things), but i'm still getting the invalid character
let me get you the base64 response and the console.log of it
HTTP response
for some reason i'm getting these weird characters
it seems like these weird characters are already in the encoded version ๐ค
Maybe the problem comes from my call to the API / to the API itself
not proficient in that regard, but you could try explicitly converting it to base64 with btoa on your server side before applying atob at your client
I'm not the one who is in charge of the API unfortunately, where shoud I do this conversion ?
I checked the string you sent and the characters you pointed out are just not renderable in the font you are using. They are not meant to be read by humans anyway, but stored in a pdf file and viewed with appropriate software
Interesting, I suppose that a PDF converter library can work with these
I mean... it's literally the contents of a PDF file. When you open any PDF file you have lying around with a text editor you will see equally scrambled content. You said yourself the API provides a PDF file, so it is no wonder you can not read it in plain text. It is meant to be saved as .pdf.
The thing is that I wanted to use an array buffer to create a blob object to recreate the PDF temporarily to show it to the user
I've found a workaround : not use $.ajax() for this solution since it doesn't support blob responses, i use the good'old XMLHttpRequest :