Home > OS >  Postman can download / display pdf but browser cannot
Postman can download / display pdf but browser cannot

Time:12-31

I have an endpoint that decodes a base64 pdf string, creates a buffer out of it, then sends that buffer back as the response. I have the headers set to:

Content-Type: application/pdf
Content-Disposition: attachment; filename="<my_filename>.pdf"

When I hit this endpoint from postman, it correctly shows / downloads the pdf (depending on if I do send or send and download). However, if I hit this endpoint from my react app, it doesn't start the download. I don't have popups blocked and I am receiving the buffer from the request.

I've tried not decoding the base64 string and sending the response back like:

res.status(200).send(`data:application/pdf;base64,${base64String}`);

but that didn't work for either postman or the browser.

I'm not sure what I'm missing here. If postman is correctly getting the information it needs to both display and download the pdf, I can't imagine I'm too far from getting the browser to be able to do the same.

CodePudding user response:

This post here may help you with downloading file when you have base64 string.

https://stackoverflow.com/a/59578316/17759066

  • Related