Re: Local images and the browser widget

2018-07-29 Thread Stephen MacLean via use-livecode
Hi Mike,

Thanks for that! I was doing the same thing at the same time:)

My code for setting up the server:

local sTempMedia


command setTempMedia

### Set the location of the tempMedia folder

# set the defaultFolder to the folder containing the stackfile

set the itemDelimiter to slash

get the effective filename of this stack

#set tempMedia folder location

put item 1 to - 2 of it & "/tempMedia" into sTempMedia

end setTempMedia


on startHTTPServer

# Launch httpd server to serve local images

setTempMedia

httpdStart "NewRequest", 8090, "imgEngine Server"

end startHTTPServer


on stopHTTPServer

httpdStop 8090

end stopHTTPServer


on NewRequest pSocketID, pRequest

local tPath

put sTempMedia & pRequest["resource"] into of tPath

if there is a file tPath then

local tData

put url ("binfile:" & tPath) into tData

httpdResponse pSocketID, 200, tData

else

-- not found

httpdResponse pSocketID, 404

end if

end NewRequest


My code for embedding it:
# tFileName is just the name of the file. i.e. MyFile.jpg
put "http://localhost:8090/; & (tFileName) into tHero

# other code would follow to meld tHero into my html

and works just amazingly well!!

Thanks again for all your help!

I sure hope this helps someone else as well!

Best,

Steve

> On Jul 29, 2018, at 8:02 PM, Mike Bonner via use-livecode 
>  wrote:
> 
> 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",,"My Picture Server" --start the server on
> port 
>   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("[[tLine]]") & 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@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@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.. >> 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 

Re: Local images and the browser widget

2018-07-29 Thread Mike Bonner via use-livecode
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",,"My Picture Server" --start the server on
port 
   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("[[tLine]]") & 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@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@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..  > 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@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 "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 " >> & ">" 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@lists.runrev.com
> >> Please visit this url to subscribe, unsubscribe and manage your
> >> 

Re: Local images and the browser widget

2018-07-29 Thread Stephen MacLean via use-livecode
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 
>  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..  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@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 "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 "> & ">" 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@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@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@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: Local images and the browser widget

2018-07-29 Thread Stephen MacLean via use-livecode
No, the Folder is "ITB pubEngine”. The %20 is an URL escape for a space.

I was trying to avoid the relative path problems by giving it an absolute path, 
but that doesn’t seem to work.

Best,
Steve

> On Jul 29, 2018, at 4:58 PM, Peter Bogdanoff via use-livecode 
>  wrote:
> 
> It is very probably the file path.
> 
> Is:
> ITB%20pubEngine 
> 
> the actual name of the folder?
> 
> Peter
> 
> 
>> On Jul 29, 2018, at 1:31 PM, Stephen MacLean via use-livecode 
>>  wrote:
>> 
>> ox/ITB%20pubEngine/tempMedia/995786d6-4429-4821-8b21-8e811289e12c.jpg 
>> "
>>  & ">" into tHTML
> 
> ___
> use-livecode mailing list
> use-livecode@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@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: Local images and the browser widget

2018-07-29 Thread Mike Bonner via use-livecode
Sorry, that should have been.. Set the url to   "file
:///Users/steve/Dropbox/I 
TB%20pubEngine/tempMedia/995786d6-4429-4821-8b21-8e811289e12c.jpg"

On Sun, Jul 29, 2018 at 3:03 PM Mike Bonner  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..  995786d6-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@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 "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 "> & ">" 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@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@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: Local images and the browser widget

2018-07-29 Thread Mike Bonner via use-livecode
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..  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@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 "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 " & ">" 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@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@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: Local images and the browser widget

2018-07-29 Thread Peter Bogdanoff via use-livecode
It is very probably the file path.

Is:
ITB%20pubEngine 

the actual name of the folder?

Peter


> On Jul 29, 2018, at 1:31 PM, Stephen MacLean via use-livecode 
>  wrote:
> 
> ox/ITB%20pubEngine/tempMedia/995786d6-4429-4821-8b21-8e811289e12c.jpg 
> "
>  & ">" into tHTML

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode