Trouble with sendHttpGetRequest and binary data

Hello,

I’m on snapshot 3.1.0 build 2144 on a synology NAS and have some trouble with sendHttpGetRequest retrieving binary (jpg) data. The requested URL works in a browser and it works directly using the telegram binding.
Since I want to pre-process the jpg’s before I send it, I need to save it before, but the resulting data seems to be invalid.

The size of the received buffer seems reasonable (approx. the same size as the resulting picture in browser) but the buffer contains approx. 90% zero and the saved file is invalid.
Currently I didn’t see my quirx in the code or thinking. The following is an extract of my JS rule:


var FileOutputStream = Java.type("java.io.FileOutputStream");
var Actions = Java.type("org.openhab.core.model.script.actions.Things");
var HTTP = Java.type("org.openhab.core.model.script.actions.HTTP");

    ... additional code here ...

    url = "/webapi/" + cameraPath + "?&version=9&id=" + cameraId + "&profileType=0&api=SYNO.SurveillanceStation.Camera&method=GetSnapshot&preview=true&_sid=" + this.currentSid;
    //->this works
       var telegramAction = Actions.getActions("telegram","telegram:telegramBot:XXXXXXXX");
       telegramAction.sendTelegramPhoto(ip+url, "xxx");

    // Get Snapshot
    var binResult = HTTP.sendHttpGetRequest(ip + url, 5000);
    if (binResult != null) {
       var fos = new FileOutputStream("/var/tmp/test.jpg");
       var len = binResult.length;
       logger.info("binResult.length " + len);
       
       //output some data from result
       byteToHexString(binResult);
       //a simple call to fos.write(binResult) writes 1kb???
       for (var i = 0; i < len; i++)
         fos.write(binResult[i]);
       fos.close();
    } 

The output of some byte of the buffer looks like this:

2021-01-24 00:12:31.422 [INFO ] [org.openhab.rule.Surveillance ] - binResult.length 284631
2021-01-24 00:12:31.423 [INFO ] [org.openhab.rule.Surveillance ] - 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x1 0x0 0x0 0x0 0x0 0x0 0x3 0x0 0x0 0x0 0x3 0x6 0x0 0x7 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x2 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0

Br,
Stefan