1

In this post (Creating a Blob from a base64 string in JavaScript) they take base64 and convert to a byte array. I haven't been able to figure out how to convert byte array back in to base64 code.

I tried using fromCharCode() and btoa() but had no luck.

Any tips on how to do this?

EDIT: Here is my code:

function decode_byteArray(result){
                var binary = '';
                var bytes = new Uint8Array(result);
                var len = bytes.byteLength;
                for (var i =0; i < len; i++){
                    binary += String.fromCharCode(bytes[i]);
                }
                return window.btoa(binary);

}

This returns nothing when I try to print it out. The responseText from the XMLHTTPRequest does print out the byte array however.

user12981480
  • 39
  • 1
  • 5
  • Have you considered this https://stackoverflow.com/questions/12710001/how-to-convert-uint8-array-to-base64-encoded-string – Shiko Mar 17 '20 at 22:14
  • here is an example [https://stackoverflow.com](https://stackoverflow.com/questions/9267899/arraybuffer-to-base64-encoded-string) – SwissCodeMen Mar 17 '20 at 22:16
  • Please show us your attempt, otherwise we cannot help you find the problem in your code – Bergi Mar 17 '20 at 22:47
  • Ok I tried a method from a comment above and still nothing. I added the code above – user12981480 Mar 17 '20 at 22:54

0 Answers0