Local images and the browser widget

Mike Bonner bonnmike at gmail.com
Sun Jul 29 20:02:59 EDT 2018


Decided to try using the httpd library, and it seems to work pretty
nicely.  If you want to set up a very simple web picture viewer (VERY
simple) the following code is a working but minimal start.

local sBaseDir
on mouseup
   httpdstart "newrequest",8888,"My Picture Server" --start the server on
port 8888
   put specialfolderpath("desktop") & "/pics" into sBaseDir -- Set this to
the folder that contains your pictures
end mouseup

on newRequest pSocketId,pRequest -- handle requests
   if pRequest["resource"] is "/" then -- if the request has no filename,
give the directory index of jpg files. (I only coded for jpegs)
      put files(sBaseDir) into tFiles
      repeat for each line tLIne in tFiles
         put merge("<a href=[[tLine]]>[[tLine]]</a><br>") & cr after tData
-- build up the response data for each file
      end repeat
      httpdresponse pSocketId,200,tData -- send the index
   else
      put "Content-Type: image/jpeg ;" into pHeader -- set the content type
to jpeg
      put URL("binfile:" & sBaseDir & pRequest["resource"]) into tData --
read the image file and pop it into tData (binary mode)
      httpdresponse pSocketId,200,tData,pHeader -- send the picture data,
200 ok code, and set the correct header for picture data
   end if
end newRequest

If your filenames/paths have spaces, you'd have to jump through some hoops
to get it to work, and your base path has that space in it, so not sure how
to get it working. Actually, nevermind.  If you change spaces in your
baseurl to "\ " it may work?  I couldn't make it work here (on windows)
despite trying a whole bunch of ideas, so I cheated and made sure there
were no spaces.

On Sun, Jul 29, 2018 at 3:21 PM Stephen MacLean via use-livecode <
use-livecode at lists.runrev.com> wrote:

> Thanks Mike, yes that does work for just displaying the image.
>
> I’m building HTML on the fly and wanted to include the local image if
> there was one, for testing. This will be a moot point for production as
> everything will be served via a web server, but I was hoping to see this
> for testing.
>
> I will be looking to the new http server LC has as I will need it anyway
> for doing some API things with this engine.
>
> Thanks again to all!
>
> Best,
> Steve
>
> > On Jul 29, 2018, at 5:03 PM, Mike Bonner via use-livecode <
> use-livecode at lists.runrev.com> wrote:
> >
> > If you just need to see the image, you can do it by changing your
> method..
> >
> > Instead of setting the htmltext, it should work to set the url to  "
> > http://Users/steve/Dropbox/ITB%20pubEngine/tempMedia/99578
> > 6d6-4429-4821-8b21-8e811289e12c.jpg"
> >
> > I'm not expert, but I think there is some type of cross-domain security
> > thing interfering here.  A web page shouldn't be able to force access to
> a
> > file on your system due to security, unless the page originates with you.
> > And I THINK that directly setting the html basically means there is no
> base
> > domain, so it will refuse to show the image.  Again, not an expert, so
> i'm
> > just making a wag.
> > If you need more control, you can likely create an html file on the fly
> and
> > point your url to that, at which point you can use relative addressing
> for
> > your pictures.  So, if you created the html file with your code in the
> same
> > folder as your stack, you could then place.. <img src=tempMedia/ 99578
> > 6d6-4429-4821-8b21-8e811289e12c.jpg> into the file and it will likely
> work.
> >
> > Another thing you might look into is running your own simple http server
> > (which LC now makes easy) so that you can set up a simple server and set
> > the url to http://localhost:8080/index.html  (or whatever port number
> you
> > wish, and again, use relative pathing.
> >
> > Either of these 2 methods is easier than using long, easily mangled
> > absolute paths.   I haven't delved into the self run server yet, but I
> > suspect you can do interesting things with it. (Or use the old revhttpd
> > stack which I HAVE used, and know that it works really well and can do
> > awesome stuff too)
> >
> >
> >
> > On Sun, Jul 29, 2018 at 2:32 PM Stephen MacLean via use-livecode <
> > use-livecode at lists.runrev.com> wrote:
> >
> >> Almost afraid to ask this because I feel like it’s a path issue with
> >> Relative vs Absolute… Remote images display fine in a browser widget,
> but
> >> local image files don’t seem to.
> >>
> >> This works (displays the image) in script and in the message box:
> >> put "<img src=" & "http://www.trumbull-ct.gov/images/BoyScouts.jpg" &
> ">"
> >> into tHTML
> >>
> >> set the htmlText of widget "finished_html_content" to tHTML
> >>
> >>
> >> This does not (Image not displayed) in script or the message box:
> >> put "<img src=" &
> >>
> "file:///Users/steve/Dropbox/ITB%20pubEngine/tempMedia/995786d6-4429-4821-8b21-8e811289e12c.jpg"
> >> & ">" into tHTML
> >>
> >> set the htmlText of widget "finished_html_content" to tHTML
> >>
> >>
> >> Sorry about bombarding the list!
> >>
> >> Thanks,
> >>
> >> Steve
> >> _______________________________________________
> >> use-livecode mailing list
> >> use-livecode at lists.runrev.com
> >> Please visit this url to subscribe, unsubscribe and manage your
> >> subscription preferences:
> >> http://lists.runrev.com/mailman/listinfo/use-livecode
> > _______________________________________________
> > use-livecode mailing list
> > use-livecode at lists.runrev.com
> > Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode



More information about the use-livecode mailing list