0

When I fire a async call to a server, I receive the base64 data of a PDF file (binary data). I want to convert this base64 data to binary and give the user as a file from browser side. I found downloadify for downloading. But I am still stuck with the part to convert base 64 encoded data to binary data in JS

Yi Jiang
50.2k16 gold badges139 silver badges137 bronze badges
asked Oct 6, 2011 at 9:48

2 Answers 2

1

Why convert ? ;) Just serve your link as data:application/pdf;base64, and then you base64 encoded pdf.

Will not work in old IE, of course. But should work in most modern browsers.

http://en.wikipedia.org/wiki/Data_URI_scheme

answered Oct 6, 2011 at 10:21

Comments

0

Even if you converted the base64 data to binary in javascript (and I find it extremely strange that a server would even do that - just send the binary data in the first place), you will not be able to generate a download link in javascript.

So there is no point in writing the conversion code.

Have the server send the binary data directly with the proper Content-Type: and Content-Disposition: headers.

You may even be able to add the Content-Encoding: base64 header and the browser will convert it on its own.

answered Oct 6, 2011 at 9:51

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.