sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Web dialog not displaying local image

    Scheduled Pinned Locked Moved Developers' Forum
    7 Posts 3 Posters 843 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      honkinberry
      last edited by

      I have a web dialog that is being migrated from local html to being remotely hosted.
      The only part that is not working, is the setting of the image source. It must be some sort of permissions issue I figure.
      I am firing something like:
      d.execute_script("document.getElementById('#{myimg}').src='file:///path/image.jpg'")
      Which works fine if the html is local!

      If this is some security built into the Safari web dialog engine.... Do I have to feed the image as a binary string?

      Many thanks for any help!

      --J

      1 Reply Last reply Reply Quote 0
      • D Offline
        driven
        last edited by

        what does WebInspector tell you when you run it on the webdialog in SU...

        where is the html page hosted?

        does the image need to be dynamically loaded?

        and yes there a couple of base64 encoded images used in examples in the forum...

        search for toolbar button may find one...

        john

        learn from the mistakes of others, you may not live long enough to make them all yourself...

        1 Reply Last reply Reply Quote 0
        • K Offline
          kaas
          last edited by

          normally the 'link' for web data is http://www.url.com/images/image.jpg
          is the result of your [file://path](file://path) something similar?

          1 Reply Last reply Reply Quote 0
          • H Offline
            honkinberry
            last edited by

            To recap, moved an HTML page from living in its plugin folder, to living on our web server.
            Everything with it is working fine, except for setting the image source to a local jpg.

            It does need to be dynamically set.
            When I inspect it, the image SRC is set, the image is just not displaying.

            Thanks for the tip on base64, it's looking like I'll need to go that route.

            --J

            1 Reply Last reply Reply Quote 0
            • D Offline
              driven
              last edited by

              kaas reminds me that when running my own server I used something like...

              src="file;//localhost#{/path/to/file}"
              

              I'll see if I can find any of that stuff...

              john

              learn from the mistakes of others, you may not live long enough to make them all yourself...

              1 Reply Last reply Reply Quote 0
              • H Offline
                honkinberry
                last edited by

                Okay, so it is just a permissions issue, browsers don't allow loading a local image from a remote page.
                So in terms of feeding the image to the dialog, I'm not having success. Here is what I have, which is not working:

                
                require "base64"
                jpg = "/path_to_image/fancy_image.jpg"
                s = File.binread(jpg)
                b = Base64.encode64(s)
                @dialog.execute_script("document.getElementById('preview').src='data;image/jpg;base64, #{b}'")
                
                

                I'm sure I screwed up something simple, thanks helping me to find out what!

                --J

                1 Reply Last reply Reply Quote 0
                • D Offline
                  driven
                  last edited by

                  here's that toolbar example http://sketchucation.com/forums/viewtopic.php?p=363402#p363402...

                  personally I avoid jpg like the plague and would go for png...

                  
                  require 'base64'
                  File.open('imagetobase64.png', 'r') do |image_file|
                  puts Base64.encode64(image_file.read)
                  end
                  

                  john

                  learn from the mistakes of others, you may not live long enough to make them all yourself...

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  • First post
                    Last post
                  Buy SketchPlus
                  Buy SUbD
                  Buy WrapR
                  Buy eBook
                  Buy Modelur
                  Buy Vertex Tools
                  Buy SketchCuisine
                  Buy FormFonts

                  Advertisement