I am new to nodejs and am trying to set up a server where i get the exif information from an image. My images are on S3 so I want to be able to just pass in the s3 url as a parameter and grab the image from it.
I am u using the ExifImage project below to get the exif info and according to their documentation:
"Instead of providing a filename of an image in your filesystem you can also pass a Buffer to ExifImage."
How can I load an image to the buffer in node from a url so I can pass it to the ExifImage function
ExifImage Project: https://github.com/gomfunkel/node-exif
Thanks for your help!
Buffers allocate raw memory outside the V8 heap. Buffer class is a global class so it can be used without importing the Buffer module in an application. Creating Buffers: Followings are the different ways to create buffers in Node. js: Create an uninitiated buffer: It creates the uninitiated buffer of given size.
The buffers module provides a way of handling streams of binary data. The Buffer object is a global object in Node. js, and it is not necessary to import it using the require keyword.
Try setting up request like this:
var request = require('request').defaults({ encoding: null }); request.get(s3Url, function (err, res, body) { //process exif here });
Setting encoding
to null
will cause request to output a buffer instead of a string.
Use the axios:
const response = await axios.get(url, { responseType: 'arraybuffer' }) const buffer = Buffer.from(response.data, "utf-8")
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