I am using axios to request an image from a url like this:
const response = await axios.get('https://asite.dom/image/url', { responseType: 'arrayBuffer' });
I don't need and don't want to save the file locally. I just need the plain binary data for checking the image dimensions.
Thus I don't want to do this
const bufferImage = Buffer.from(response.data, 'binary');
because that's a buffer not the binary data.
I've tried to access
response.data
directly, but that's not the image's binary data either.
Can anybody help me with this?
Just tested this and it works:
const response = await axios.get(
'https://example.com/image.png', { responseType: 'arraybuffer' }
);
const bin = response.data.toString('binary');
console.log(bin);
The key seems to be that you capitalized the b in arraybuffer. Also, response.data is already a buffer, so you can just directly convert it to a string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With