Skip to content

btoa issue in bufferToBase64 function #2

@harrybaines

Description

@harrybaines

Been following the buildspace AI avatar generator project and loving it so far!

I did come across an issue when creating the React app. In the bufferToBase64 function:

const bufferToBase64 = (buffer) => {
    let arr = new Uint8Array(buffer);
    const base64 = btoa(
        arr.reduce((data, byte) => data + String.fromCharCode(byte), '')
    )
    return `data:image/png;base64,${base64}`;
};

I had an issue with btoa not being defined:

error - ReferenceError: btoa is not defined

I did an npm install --save buffer and added import { btoa } from "buffer"; to pages/api/generate.js which fixed my issue. Not sure if anyone else had the same issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions