Facility Control

 View Only
  • 1.  Save locally an image from an http url in Dashboard [SOLVED]

    Posted 11-22-2019 14:07

    Hi,
    I need to set the background of a button with an image taken from a http url (let's say http://site.com/image.png). This is easy.


    The problem is that I need to save that image (WHITHIN DASHBOARD), cause at the same url the image is continuously changing.
    So:
    1. Is there a way to save an image locally from a url in Dashboard?
    2. If not, is there a way to execute an external script, like a powershell one in Windows, to do that work for me?

    Thanks,
    Raffaele



  • 2.  RE: Save locally an image from an http url in Dashboard [SOLVED]

    Posted 11-22-2019 14:12

    To clarify myself: the saving itself should be operated by Dashboard, cause the image has to be saved in the moment in which I click on a specific button.


    #DashBoard


  • 3.  RE: Save locally an image from an http url in Dashboard [SOLVED]

    Posted 11-22-2019 16:27

    Hi Raffaele,

    I have attached a code snippet for a custom panel that saves a local image from an HTTP URL.

    This example uses an ogScript.asyncHTTP() command to retrieve the image and a callback function is triggered to save the file. The ogscript.saveToFile() command accepts a boolean argument which can be set to true in order to overwrite the file if it already exists.

    Please let me know if you have any questions.

     

    <abs contexttype="opengear" gridsize="20" id="_top" keepalive="false" style="">
    <meta>
    <params>
    <param access="1" maxlength="0" name="url" oid="url" type="STRING" value="https://2wk12w2dk3733zyjdf3secd9-wpengine.netdna-ssl.com/wp-content/uploads/2018/03/Ross-Logo-Living-Live.png" widget="default"/>
    <param access="1" maxlength="0" name="filename" oid="filename" type="STRING" value="ross.png" widget="file-picker"/>
    </params>
    <api>

    </api>
    </meta>
    <label height="80" left="40" name="Using a URL for an image" style="txt-align:west;size:Bigger;" top="20" width="520"/>
    <button buttontype="push" height="100" left="40" style="bg-u:https://2wk12w2dk3733zyjdf3secd9-wpengine.netdna-ssl.com/wp-content/uploads/2018/03/Ross-Logo-Living-Live.png;bg-fill:fit;bg-insets:10,10,10,10;" top="100" width="200"/>
    <label height="80" id="" left="40" name="Saving a URL image to file" style="txt-align:west;size:Bigger;" top="280" width="540"/>
    <table height="40" left="40" oid="url" top="360" width="660">
    <tr>
    <label anchor="east" fill="none" insets="0,0,0,5" name="url" weightx="0.0"/>
    <param anchor="west" expand="true" fill="both" oid="url" showlabel="false" weightx="1.0" weighty="1.0"/>
    </tr>
    </table>
    <table height="40" left="40" oid="filename" top="420" width="660">
    <tr>
    <label anchor="east" fill="none" insets="0,0,0,5" name="filename" weightx="0.0"/>
    <param anchor="west" expand="true" fill="both" oid="filename" showlabel="false" weightx="1.0" weighty="1.0"/>
    </tr>
    </table>
    <button buttontype="push" height="40" left="40" name="Save" top="480" width="140">
    <task tasktype="ogscript">
    function callbackGetUrl(resultStr)
    {
    ogscript.debug("resultStr is " + resultStr);
    ogscript.saveToFile(params.getValue('filename', 0), resultStr, false);
    ogscript.rename("savemessage", "url saved to " + params.getValue('filename',0));
    }


    ogscript.asyncHTTP(params.getValue('url', 0), 'GET', null, null, callbackGetUrl, false);</task>
    </button>
    <label height="40" id="savemessage" left="200" name="" style="txt-align:west;" top="480" width="500"/>
    </abs>

    #DashBoard


  • 4.  RE: Save locally an image from an http url in Dashboard [SOLVED]

    Posted 11-22-2019 16:42

    Thanks David, this is perfect!


    #DashBoard