Now I have a string of a MD5 hex digest for a file, and I want to convert it to base64 in order to use the Content-MD5 HTTP header when uploading it.
Any help would be appreciated
Now I have a string of a MD5 hex digest for a file, and I want to convert it to base64 in order to use the Content-MD5 HTTP header when uploading it.
Any help would be appreciated
var hexArray = myHexString
.replace(/\r|\n/g, "")
.replace(/([\da-fA-F]{2}) ?/g, "0x$1 ")
.replace(/ +$/, "")
.split(" ");
var byteString = String.fromCharCode.apply(null, hexArray);
var base64string = window.btoa(byteString);
See here for btoa docs: https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/btoa
Also for polyfill: https://stackoverflow.com/a/23190164/275501
Modern browsers has built in functions for this: https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding
For older browsers you'll need a library such as https://github.com/beatgammit/base64-js