Convert base64 string to a file in javascript

I lately realized that people who are using my technique to convert a file to a base64 string in javascript are searching out for a solution to convert base64 to a file. This article mainly concentrates on converting the base64 back to the respective file with their respective formats.

There are many ways to achieve it.
Let’s say you know the base64 string is a pdf object , then just use a line

Different browsers will behave differently on this statement, some will open the pdf in a new window where as some will pop-up a window which expects the user to open the file with a specific application based on operating system or save the file.

If your requirement is to convert the base64 string to TIFF or DOC etc then prefer converting the base64 string to a blob and downloading it since many browsers would not support opening of files with those extensions.

Assuming you get the MIME type with the base64 string in a response object,

I hope the article is helpful.

Happy Coding……..:)

Tagged as: ,