Base64 - Buffer - API Request

Hey @pod2! Thanks for reaching out.

It definitely depends on the API that you're hitting, but I've generally had more success working with the base64 string instead of converting it. Here's one example of constructing a raw multipart payload, for example.

In general, though, the algorithm for converting a base64 string into a Blob should be similar to the below.

// Decode the Base64 string
    const binaryString = atob(base64);
    const len = binaryString.length;
    const bytes = new Uint8Array(len);

    // Convert binary string to byte array
    for (let i = 0; i < len; i++) {
        bytes[i] = binaryString.charCodeAt(i);
    }

    // Create a Blob from the byte array
    return new Blob([bytes], { MIME_TYPE });

Let me know if you have any follow up questions about that! I'm happy to take a look at your specific use case, as well. :+1:

1 Like