Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Einsteigerfragen
    4. [gelöst] Datenpunkt mit base64 in Bilddatei schreiben

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    [gelöst] Datenpunkt mit base64 in Bilddatei schreiben

    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      accessburn @OliverIO last edited by

      @oliverio Okay, sorry...

      Ich habe einen Datenpunkt mit einer Grafik als base64 und ich möchte ihn auf dem Server direkt speichern, also quasi unter userfiles...

      Und würde das als Blockly gehen?

      OliverIO 1 Reply Last reply Reply Quote 0
      • OliverIO
        OliverIO @accessburn last edited by

        @accessburn

        von blockly hab ich keine ahnung.
        aber ich denke, das die formatangabe beim speichern der datei bei blockly direkt nicht enthalten ist.
        das muss man dann in einem funktionsblock als javascript eintragen

        1 Reply Last reply Reply Quote 0
        • A
          accessburn last edited by

          Okay, ich komme null weiter...

          data:image/png;base64,iVBORw0KGgoAAAANSUhEUg...
          

          Das steht im Datenpunkt und ich möchte ein Script haben dass mir beim ändern des Datenpunkts, das Bild daraus auf das Laufwerk legt. Kann mir da jemand helfen?

          1 Reply Last reply Reply Quote 0
          • OliverIO
            OliverIO last edited by OliverIO

            @accessburn

            https://stackoverflow.com/questions/6926016/how-can-i-save-a-base64-encoded-image-to-disk

            let imgstr = getState("datepunktidmitbild");
            var base64Data = imgstr.rawBody.replace(/^data:image\/png;base64,/, "");
            require("fs").writeFile("out.png", base64Data, 'base64', function(err) {
              console.log(err);
            });
            
            A 1 Reply Last reply Reply Quote 0
            • A
              accessburn @OliverIO last edited by

              Danke @oliverio , habe ich einfach mal kopiert und die werte angepasst.
              76938d8c-b342-4f18-97dc-7499596aea69-image.png

              haus-automatisierung OliverIO 2 Replies Last reply Reply Quote 0
              • haus-automatisierung
                haus-automatisierung Developer Most Active @accessburn last edited by haus-automatisierung

                @accessburn

                const value = getState('mihome-vacuum.0.cleanmap.map64').val;
                const base64str = value.replace(/^data:image\/png;base64,/, '');
                const base64data = Buffer.from(base64str, 'base64');
                
                writeFile('0_userdata.0', '/cleanmap.png', base64data, (err) => {
                    if (!err) {
                        console.info('File written');
                    } else {
                        console.error(err);
                    }
                });
                
                A 1 Reply Last reply Reply Quote 0
                • A
                  accessburn @haus-automatisierung last edited by

                  @haus-automatisierung

                  on({ id: [].concat(['mihome-vacuum.0.cleanmap.map64']), change: 'ne' }, async (obj) => {
                  
                      const value = getState('mihome-vacuum.0.cleanmap.map64').val;
                      const base64str = value.replace(/^data:image\/png;base64,/, '');
                      const base64data = Buffer.from(base64str, 'base64');
                      
                      writeFile('0_userdata.0', '/cleanmap.png', base64data, (err) => {
                          if (!err) {
                              console.info('File written');
                          } else {
                              console.error(err);
                          }
                      });
                  
                    // console.error(getState('mihome-vacuum.0.cleanmap.map64').val);
                  });
                  

                  Vielen Dank, das klappte schon mal auf anhieb.
                  Macht das so Sinn mit dem "change"?

                  haus-automatisierung 1 Reply Last reply Reply Quote 0
                  • haus-automatisierung
                    haus-automatisierung Developer Most Active @accessburn last edited by haus-automatisierung

                    @accessburn sagte in Datenpunkt mit base64 in Bilddatei schreiben:

                    Macht das so Sinn mit dem "change"?

                    Ja, wenn es nur eine ID ist, würde ich mir aber das Array sparen:

                    on({ id: 'mihome-vacuum.0.cleanmap.map64', change: 'ne' }, async (obj) => {
                    

                    Und Du kannst direkt mit dem Wert arbeiten (ohne den nochmal zu holen):

                    on({ id: 'mihome-vacuum.0.cleanmap.map64', change: 'ne' }, async (obj) => {
                        const value = obj.state.val;
                        const base64str = value.replace(/^data:image\/png;base64,/, '');
                        const base64data = Buffer.from(base64str, 'base64');
                        
                        writeFile('0_userdata.0', '/cleanmap.png', base64data, (err) => {
                            if (!err) {
                                console.info('File written');
                            } else {
                                console.error(err);
                            }
                        });
                    });
                    
                    A 1 Reply Last reply Reply Quote 0
                    • A
                      accessburn @haus-automatisierung last edited by

                      @haus-automatisierung sagte in Datenpunkt mit base64 in Bilddatei schreiben:

                      n({ id: 'mihome-vacuum.0.cleanmap.map64', change: 'ne' }, async (obj) => {

                      Sehr cool. Danke! ♥
                      Diese Sprache beherrsche ich einfach nicht. Bin in PHP groß geworden 😉

                      haus-automatisierung 1 Reply Last reply Reply Quote 0
                      • haus-automatisierung
                        haus-automatisierung Developer Most Active @accessburn last edited by

                        @accessburn sagte in Datenpunkt mit base64 in Bilddatei schreiben:

                        Bin in PHP groß geworden

                        Ja, ich auch.

                        Gerade 2 Tage lang alle PHP-Klassen des Online-Shops auf PHP 8.3 und strict types umgestellt...

                        A 1 Reply Last reply Reply Quote 0
                        • A
                          accessburn @haus-automatisierung last edited by

                          @haus-automatisierung
                          Na das passt ja. 🙂

                          Aber Frage, würde sich das mit Blockly umsetzen lassen?

                          haus-automatisierung 1 Reply Last reply Reply Quote 0
                          • haus-automatisierung
                            haus-automatisierung Developer Most Active @accessburn last edited by

                            @accessburn sagte in Datenpunkt mit base64 in Bilddatei schreiben:

                            würde sich das mit Blockly umsetzen lassen?

                            Zu 90%, ja.

                            1 Reply Last reply Reply Quote 0
                            • OliverIO
                              OliverIO @accessburn last edited by

                              @accessburn

                              ahja das rawbody hatte ich nicht entfernt

                              1 Reply Last reply Reply Quote 0
                              • First post
                                Last post

                              Support us

                              ioBroker
                              Community Adapters
                              Donate

                              833
                              Online

                              31.9k
                              Users

                              80.2k
                              Topics

                              1.3m
                              Posts

                              3
                              15
                              398
                              Loading More Posts
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes
                              Reply
                              • Reply as topic
                              Log in to reply
                              Community
                              Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                              The ioBroker Community 2014-2023
                              logo