To convert uint8 array to base64 encoded string with JavaScript, we use the Buffer.from
method.
For instance, we write
const u8 = new Uint8Array([65, 66, 67, 68]);
const b64 = Buffer.from(u8).toString("base64");
to call Buffer.from
with the u8
Uint8Array
to convert it to a buffer.
Then we call toString
with 'base64'
to convert it to a base64 string.