3 Replies Latest reply on Oct 19, 2014 11:28 AM by steve_ssh

    Passing a data URL as a parameter from a webviewer to filemaker file.

    madmike6537

      Hello,

       

      My ultimate goal is to pass an image that is created by my webviewer javascript code to filemaker.

       

      As far as I can tell, I cant just pass the image as a parameter (please correct me if that is not right), so I am currently trying to pass it as a dataURL string and then Decode it inside my filemaker script.

       

      Here is my code to send it to my filemaker file. The script runs, but the parameter always shows that its empty, as if nothing came accross. I am wondering if because of all the slashes and what not in the dataURL, that filemaker is not realizing that this is a string? I cant figure out how to make it more of a string then it already is though Maybe I am missing something simple...

       

      var myParam = String(dataUrl.split(',').pop());

      theURL = 'fmp://$/" & Get(FileName)& "?script=MoistureMap_Done&param=' + myParam;

       

       

      notes:

       

      dataUrl is my variable that stores the dataURL string.

      Here I am using split and pop which basically cuts off the first part of the string which is the "image/png" stuff that comes before the actual data URL. If filemaker actually needs this let me know.

       

      Thanks in advance to anyone that can help!

        • 1. Re: Passing a data URL as a parameter from a webviewer to filemaker file.
          steve_ssh


          madmike6537 wrote:

           

          I am wondering if because of all the slashes and what not in the dataURL, that filemaker is not realizing that this is a string? I cant figure out how to make it more of a string then it already is though  

           

          Hi Mike,

           

          Your thinking is sound:

           

          There is a standard procedure employed for encoding data that is being passed in a URL.

           

          The name for this is:   "URL encode/encoding" or "URI encode/encoding".

           

          If you read up a little bit on this topic, I think it will quickly make sense to you, especially since you are already intuitively sensing that there may exist such a procedure.

           

           

          In JavaScript, there are a couple of functions that you can use to perform URL-encoding.

           

          I believe that the function that you will wish to make use of is:

           

              encodeURIComponent()

           

           

          You might start by changing the second line your code to something like:

           

              theURL = 'fmp://$/" & Get(FileName)& "?script=MoistureMap_Done&param=' + encodeURIComponent( myParam );

           


          Beyond the topic of encoding:

           

          Depending on the platform this code runs on, you may run up against a limit to the amount of data that you can pass in a URL.  I don't know the limiting numbers off of the top of my head, but if you are on a Windows machine I'd be particularly wary of this possibility.

           

          Kind regards,

           

          -steve

           

           

          References:

           

          https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent

           

          http://www.w3schools.com/jsref/jsref_encodeuricomponent.asp

          • 2. Re: Passing a data URL as a parameter from a webviewer to filemaker file.
            madmike6537

            Thanks as always Steve. That function is working great and I am now able to transfer the url into filemaker. I will have to do some searching on url lengths, hopefully that doesnt present a problem later. Now to figure out how to turn it back into an image and put it into a container. So far base64Decode isnt working, or maybe I need another step

             

            Base64Decode ( Get(ScriptParameter) )

             

            Found a custom function that decodes it, then I base 64 decode that, but it still leaves me with a untitled.dat file. Darnit, thought I had it figured out

             

            EDIT; GOT IT!! Didnt realize I had to supply a file name with filemaker's decode function. Woot it works!

            • 3. Re: Passing a data URL as a parameter from a webviewer to filemaker file.
              steve_ssh

              madmike6537 wrote:

               

              EDIT; GOT IT!! Didnt realize I had to supply a file name with filemaker's decode function. Woot it works!

               

              Great news!  Thank you for posting the update with your success.

               

              Very best,

               

              -steve