I have a pdf file base64 encoded and want to attach it to an email. However, the atob function doesnt work properly if the encoded data contains domstrings which are 16bit encoded. Sometimes you have to send or output a pdf file within a text document for example, html, json, xml, but you cannot do this because binary characters will damage the syntax of the text document. Hence, we dont have to includerequire it separately. The final step uses the tostringencoding function of the buffer class to convert the data back to ascii.
It shows how to convert file into base64 string using node modules filesystem library in node js application. Previously we only cared about leaving the file on the filesystem, but this time around we converted it to a base64 string. Ideally the data or string can be transcoded between these 4 encodings without data loss. There might be scenarios where you need to convert an base64 string back to a file. In this article, youll learn how to base64 encode a string in node. If you select the decode base64 to text option, it will allow you to convert any base64 string into a human readable string.