Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Image to dataurl Node.js
var request = require('request').defaults({encoding: null});
var imgUrl = 'URL_OF_IMG';
request.get(imgUrl, function (error, rep, body) {
var data = '';
if (!error && rep.statusCode === 200) {
data = 'data:' + rep.headers['content-type'] + ';base64,' + new Buffer(body).toString('base64');
}
// Do something with data
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.