How to Write Doorbird Base64 Image to Disk and Convert to JPG in ECMA-2021?

  • Platform information:
    • Hardware: Pi4
    • OS: Raspbian
    • Java Runtime Environment: java version “11.0.16" 2022-07-19
    • openHAB version: 3.4.0 Stable

I just searched the forum and tried to figure out how I can write the the base64 encoded image from my doorbird to disk in jpg format.

I would like to do that in ecma-2021 scripting. Maybe I got confused between solutions in Java, JavaScript and others and mixed up everything.

The out commented var CamaeraImage, I copied directly from the API, using this the JPG File is written correctly. Obviously I have problems to get the right string from the item and convert it correctly.

Any hint how i have to exctract the correcet base64 image string and convert it, is highly appriciated

configuration: {}
  - id: "2"
      thingUID: doorbird:d101:DoorbirdD101
      channelUID: doorbird:d101:DoorbirdD101:doorbell
    type: core.ChannelEventTrigger
conditions: []
  - inputs: {}
    id: "1"
      type: application/javascript;version=ECMAScript-2021
      script: >+
        var JDatatypeConverter = Java.type('javax.xml.bind.DatatypeConverter');
        var JFile = Java.type('');
        var JFileOutputStream = Java.type('');
        var JOutputStream = Java.type('');

        var CameraImage = items.getItem("DoorbirdDoorbellD101_Image").state.toString();
        //var CameraImage = "/9j/4AAQSkZJRgABA.........";
        var data = JDatatypeConverter.parseBase64Binary(CameraImage);

        var f = new JFile("/etc/openhab/html/" + "DoorbirdDoorbellD101_Image" + ".jpg");
        var os = new JFileOutputStream(f);

    type: script.ScriptAction

I get this log, i was expecting the string as it is in the API request.

2022-12-25 11:09:28.321 [INFO ] [mation.script.ui.Doorbird_Save_Image] - raw type (image/jpeg): 22419 bytes
2022-12-25 11:09:28.323 [INFO ] [mation.script.ui.Doorbird_Save_Image] - [B@1b2c771