1
app.getImage = function() {

    var image = Meteor.http.get("https://turtlerock-discourse.global.ssl.fastly.net/user_avatar/talk.turtlerockstudios.com/takran/45/879.png", {

    });
    var prefix = "data:image/png;base64,";
    var imagebase64 = new Buffer(image.content, 'binary').toString('base64');
    imagebase64 = prefix + imagebase64;

    console.log(imagebase64);
    return imagebase64;
}

but I am not seeing results, any help? This is a dummy text for the error.

nicolsondsouza
  • 426
  • 3
  • 15

2 Answers2

3

a pure Meteor solutions:

    var response = HTTP.call('GET', url,{npmRequestOptions: { encoding: null }})

    var data = "data:" + response.headers["content-type"] + ";base64," + new Buffer(response.content).toString('base64');
cesarve
  • 274
  • 3
  • 9
0

This is how I fixed this issue.

app.getImage = function(){

var myrequest = request.defaults({ encoding: null });

var fut = new Future(); 
var options = {
    "url" : "https://any.domain.com/any.png"
}
myrequest.get(options, function (error, response, body) {
    if (!error && response.statusCode == 200) {
        var data = "data:" + response.headers["content-type"] + ";base64," + new Buffer(body).toString('base64');
        fut.return(data);
    }
    else
        fut.return(null);
});

return fut.wait();

}

I was assuming this solution should have come with meteor code itself, but it doesn't, I had to use nodejs way to do it.

I will still be waiting for someone to post an answer based on pure meteor way.

nicolsondsouza
  • 426
  • 3
  • 15