Skip to content

Instantly share code, notes, and snippets.

@brexis
Created June 12, 2015 15:14
Show Gist options
  • Save brexis/0018f3a3921b6816c7a6 to your computer and use it in GitHub Desktop.
Save brexis/0018f3a3921b6816c7a6 to your computer and use it in GitHub Desktop.
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