如何将图像从url加载到nodejs中的缓冲区中 [英] how to load an image from url into buffer in nodejs
问题描述
我是nodejs的新手,我正在尝试设置一个服务器,我从图像中获取exif信息。我的图像在S3上,所以我希望能够将s3 url作为参数传递并从中获取图像。
我使用的是ExifImage项目下面是获取exif信息并根据他们的文档:
您可以将缓冲区传递给ExifImage,而不是在文件系统中提供图像文件名。 / p>
如何将图像从网址加载到节点中的缓冲区,以便将其传递给ExifImage函数
ExifImage项目:
https://github.com/gomfunkel/node-exif
感谢您的帮助!
尝试设置请求像这样:
var request = require('request')。defaults({encoding:null});
request.get(s3Url,function(err,res,body){
// process exif here
});
将编码
设置为 null
将导致请求输出缓冲区而不是字符串。
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!
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.
这篇关于如何将图像从url加载到nodejs中的缓冲区中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!