base64 to blob 1

base64 to blob

const byteCharacters = atob(b64);
const byteNumbers = new Array(byteCharacters.length);
for (let i = 0; i < byteCharacters.length; i++) {
  byteNumbers[i] = byteCharacters.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);
const blob = new Blob([byteArray], {type: 'audio/mp3'});

Here is what the above code is Doing:
1. We're using the atob() function to decode the base64 encoded string.
2. We're creating a Uint8Array typed array from the decoded string.
3. We're creating a Blob from the typed array.
4. We're creating a URL from the Blob.
5. We're creating an audio element and setting its src to the URL.
6. We're appending the audio element to the document.

Similar Posts