How to load an image from url to buffer in nodejs

My computer develop environment

1
2
node -v  //v8.1.0
npm -v //5.3.0

After http request a image url , I want the buffer for picture storage service

so the code look like:

1
2
3
4
var request = require('request').defaults({encoding: null});
request(url, function (error, response, body) {
//body default is string , but it's buffer type now
});

or

1
2
3
4
5
6
7
8
9
10
var request = require('request');

var requestSettings = {
method: 'GET',
url: url,
encoding: null
};
request(url, function (error, response, body) {
//body default is string , but it's buffer type now
});

# Mac, Nodejs

Thank you for reading.
This post is copyrighted by Liyuliang’s Blog.
If reproduced, please indicate the source: Liyuliang’s Blog
This blog uses Creative Commons Attribution-NonCommercial-Share-Sharing 4.0 International License Agreement to license.


Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×