Created
June 12, 2015 15:14
-
-
Save brexis/0018f3a3921b6816c7a6 to your computer and use it in GitHub Desktop.
Image to dataurl Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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