Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decode URL Safe Base64 in JavaScript (browser side)

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.

like image 433
wibberding Avatar asked Jan 22 '15 23:01

wibberding


2 Answers

For posterity,

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

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

like image 110
xori Avatar answered Oct 12 '22 01:10

xori


Finally found it. This does URL Safe decoding

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

like image 25
wibberding Avatar answered Oct 11 '22 23:10

wibberding