编码到base64后解压缩文件并在另一个应用程序中解码

A PDF file is being generated client-side using jsPDF, encoded in base64 using btoa(), sent to a PHP API and there it's decoded and saved as a binary file, but it isn't working and I'm getting a malformed PDF.

PHP code:

$destination = 'test/file.pdf';
$content = base64_decode($content);
$uploaded = file_put_contents($destination, $content);

If I compare both files (The pdf file downloaded directly from the frontend, which works, vs the one downloaded from the server) this is what I get:

Original PDF File fragment (I cannot disclose the full file): original one, working well

Post encode/decode one: enter image description here

What could be causing this difference? Seems to be an encoding problem?

I cannot comment, because I need 50 rep :) Leaving an answer instead.

Make sure you are doing your POST request correctly. Instead of your PDF file, try to post another file to the server, for example an image file and try to open posted image file on the server.