0

I need to get an image in the form of Buffer like in the example below: enter image description here

But when I run Buffer.from on a base64 string I'm getting Uint8Array like in the example below: enter image description here

const originalUrl =
      'https://i.picsum.photos/id/621/200/300.jpg?hmac=GgxwZqdPsVQwlM2QhfHoLU8gZ7uo_PP6oD4KmIq-ino';
const response = await axios.get(originalUrl, { responseType: 'arraybuffer' });

const base64Str = response.data.base64Slice();

// returns Uint8Array
const brfFromBase64String = Buffer.from(base64Str, 'base64');

How can I turn a base64 string into a Buffer?

1 Answer 1

1

Turn the the Uint8Array,strBuffer, into an ArrayBuffer with .buffer. Then pass it to Buffer.from to get Buffer:

const buffer = Buffer.from(strBuffer.buffer);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.