Decode URL Safe Base64 in JavaScript (browser side)

為{幸葍}努か 提交于 2019-11-27 23:53:20

问题


I am using Gmail's API to get emails from my account. The body of the message is delivered in a "URL safe base64" format. What is the best way to decode this for use? I have found some nodejs solutions, but no client side ones. window.atob does not work since it is URL safe.

Thanks for any help.


回答1:


For posterity,

atob(data.replace(/_/g, '/').replace(/-/g, '+'))

As stated by the spec https://tools.ietf.org/html/rfc4648#section-5 however because this uses atob() it does not support unicode characters and thus requires a polyfill.




回答2:


Finally found it. This does URL Safe decoding

https://github.com/dankogai/js-base64




回答3:


decodeURIComponent(atob(data))



来源:https://stackoverflow.com/questions/28100601/decode-url-safe-base64-in-javascript-browser-side

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!