Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to use a Javascript callout to get a PNG image

Not applicable

I am using a JS Callout in my proxy to get a PNG image and am running into the following issues -

1) When I use https, I get the SSL error - Received fatal alert: handshake_failure

2) With http, I get a response but it is the raw PNG data. If I make the request in Postman, I get the image rendered properly. I think it may be an encoding issue when making the request via Apigee. Is there a JS workaround used for callouts in Apigee?

Here's my current code -

var headers = {'Accept':'image/png'};

var req =newRequest("https://tile2.aerisapi.com/credentials/current_temps/500x500/40/-105/10/0.png",'GET',headers);
var exchange = httpClient.send(req);
exchange.waitForComplete();
var response = exchange.getResponse(); 

if (exchange.isSuccess()) {
    var responseObject = exchange.getResponse();
    print(responseObject);
    context.setVariable('awhere.imageResponse',responseObject.content);  
}else{
    print(exchange.getError());
}
0 10 3,512
10 REPLIES 10