Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

btoa issue in bufferToBase64 function #2

Open
harrybaines opened this issue Jan 9, 2023 · 3 comments
Open

btoa issue in bufferToBase64 function #2

harrybaines opened this issue Jan 9, 2023 · 3 comments

Comments

@harrybaines
Copy link

harrybaines commented Jan 9, 2023

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?

@AlmostEfficient
Copy link

This is likely an issue with your version of Node. Mb, should have clarified which versions this is a problem on, we missed it in QA

@harrybaines
Copy link
Author

This is likely an issue with your version of Node. Mb, should have clarified which versions this is a problem on, we missed it in QA

Cool, FYI my version was v14.19.3.

@0xAli0x
Copy link

0xAli0x commented Feb 3, 2023

const buffer = require('buffer');

const BufferToBase64 = (binaryData) => {
  return buffer.from(binaryData).toString('base64');
};

I added this in my generate.js file and it worked fine!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants