Imageview.URL in Standalone SSL sessions

The Web App I’m building uses SSL and loads images (which vary depending on user input and cookie values) from a database as blobs,
which I assign to a Session.WebPicture array, that I then use in imageViews.
This works, but loading 40 images takes a lot of time and stalls the updating of other sessions, making them all very slow.
also, nothing is cached, so each time a set of images is chosen that have been displayed before, they load all over, taking more time.

How can I simply use imageview.URL and a folder of images within the folder of my Standalone web App to set the images?
Preferably also preloading them as much is possible.

I cannot place them on a different server as that gives me SSL connection issues,
so I would much prefer to access the images in the folder next to my App, but have not found a valid way to get the correct path.

I can find the path to a specific image in a specific session, but that obviously will not work for other sessions.
The https://appname.com/framework/image.png does exist for images that Xojo embeds, such as the spinner wheel,
but my images folder is in the same folder as my App.

I suggest that you implement App.HandleURL. I did a blog post last year about how it works and what the restrictions are:

http://blog.xojo.com/2014/12/10/hell_freezes_over/

@Greg O’Lone Thanks Greg for the super fast reply.,

So for instance when I set an imageView.URL to “https://myapp.com/images/01.png”,
I could make a HandleURL that triggers on /images and then returns the path thus avoiding a page missing error?

Here is a snippet of code in HandleURL to serve pictures in the /Pics directory. For instance

http://127.0.0.1:8080/Pics/Robot100.png

dim ImagetoFetch as string if left(Request.Path,5) = "pics/" then ImagetoFetch = Right(Request.Path,len(Request.Path)-5) Dim f as folderitem = Specialfolder.Desktop.child(ImagetoFetch) If f = nil then return False else If f.Exists Then // Be aware that TextInputStream.Open coud raise an exception Dim t As TextInputStream Try t = TextInputStream.Open(f) Request.MIMEType = FileTypes1.All Request.Print t.ReadAll Catch e As IOException t.Close Return False End Try else Return False // File not found End If return True end if end if

I have used SpecialFolder.Desktop because that is where my picture was, but in a typical standalone app, it is probably a folder next to the executable, something like

App.ExecutableFileName.Parent.Child("Pics")

It is important to have all the necessary file types in FileTypes1 to correctly serve the pictures, which otherwise would show as text garble.

[quote=204089:@Michel Bujardet]Here is a snippet of code in HandleURL to serve pictures in the /Pics directory. For instance

http://127.0.0.1:8080/Pics/Robot100.png

dim ImagetoFetch as string if left(Request.Path,5) = "pics/" then ImagetoFetch = Right(Request.Path,len(Request.Path)-5) Dim f as folderitem = Specialfolder.Desktop.child(ImagetoFetch) If f = nil then return False else If f.Exists Then // Be aware that TextInputStream.Open coud raise an exception Dim t As TextInputStream Try t = TextInputStream.Open(f) Request.MIMEType = FileTypes1.All Request.Print t.ReadAll Catch e As IOException t.Close Return False End Try else Return False // File not found End If return True end if end if

I have used SpecialFolder.Desktop because that is where my picture was, but in a typical standalone app, it is probably a folder next to the executable, something like

App.ExecutableFileName.Parent.Child("Pics")

It is important to have all the necessary file types in FileTypes1 to correctly serve the pictures, which otherwise would show as text garble.[/quote]
Ok, first of all, don’t use a TextInputStream. You should use a BinaryStream for this. Next, don’t set the mime type to FileTypes1.All. If you have more than one type in there, the type will be set to ALL of them and the browser will still get confused.

JPEGs should be set to “image/jpeg”
PNGs should be set to “image/png”

[quote=204105:@Greg O’Lone]Ok, first of all, don’t use a TextInputStream. You should use a BinaryStream for this. Next, don’t set the mime type to FileTypes1.All. If you have more than one type in there, the type will be set to ALL of them and the browser will still get confused.

JPEGs should be set to “image/jpeg”
PNGs should be set to “image/png”[/quote]

I tested this particular snippet fine with Edge. It seems the two types I had I entered that where precisely png and jpeg did not confuse it ; display is good.

The intent of that short piece of code was not so much to establish the absolute reference, but to provide the OP with a direction into which elaborate his own solution. Of course, BinaryStream is better, and extensions should be taken into account to set the mime type for each. That will be easy to implement now.

Thank you.

@Michel Bujardet : Thank you for the sample; that really helps.
@Greg O’Lone : Makes sense to use a binary stream.
I should be able to get it working now. With Xojo Web Apps always using single core and thread, any web app that uses any amount of graphics needs some way to avoid the Web App becoming sluggish, so hopefully it will speed things up.

There is yet another possible improvement : instead of using your main app to serve images, have a helper on another core do that for you on another port.

Then in your main app, all you have to do is to use the URL of the server helper in it.

[quote]There is yet another possible improvement : instead of using your main app to serve images, have a helper on another core do that for you on another port.

Then in your main app, all you have to do is to use the URL of the server helper in it.[/quote]

@Michel Bujardet Thank you for that suggestion, that gave a another idea, which might even be better than using just another Xojo helper App;
I setup a new port routing 8083 which routes to the Apache server, on which the same certificate allows it to make SSL connections too.
Now I can simply use: https://myapp.com:8083/Images/image01.png in an WebImageView which now is handled nicely by Apache.

I assume Apache serves my images faster than HandleURL does in Xojo and makes the App more responsive as it only has to do the logic, not the images.
The only problem might be when people try to access it from a network that blocks that port, but it seems to run fine from my own network and my iPhone’s network.

[quote=204149:@Boudewijn Krijger]@Michel Bujardet Thank you for that suggestion, that gave a another idea, which might even be better than using just another Xojo helper App;
I setup a new port routing 8083 which routes to the Apache server, on which the same certificate allows it to make SSL connections too.
Now I can simply use: https://myapp.com:8083/Images/image01.png in an WebImageView which now is handled nicely by Apache.

I assume Apache serves my images faster than HandleURL does in Xojo and makes the App more responsive as it only has to do the logic, not the images.
The only problem might be when people try to access it from a network that blocks that port, but it seems to run fine from my own network and my iPhone’s network.[/quote]

There may be no need to setup a port, if you have your own domain. If you can place your pictures in a web accessible folder, like https://mydomain.com/images, you alleviate all the strain on your app. That is what I usually do. It is also by far the fastest way to display pictures in a Xojo Web app.

@Michel Bujardet

That would be true if my server mac was directly hooked up to the web using a public IP address, but it is behind a router on a private IP. The router re-routes only ports 80 and 443 to my App. Hence the extra port map; without a port the request would go to my web App, which has no Handler for the /images/ folder so creates a missing page response when I try to map to it.

[quote=204153:@Boudewijn Krijger]@Michel Bujardet

That would be true if my server mac was directly hooked up to the web using a public IP address, but it is behind a router on a private IP. The router re-routes only ports 80 and 443 to my App. Hence the extra port map; without a port the request would go to my web App, which has no Handler for the /images/ folder so creates a missing page response when I try to map to it.[/quote]

I see.