Download from the HTMLViewer on LINUX

Since it’s clear as mud in the Xojo docs, is there a code flow for providing downloads from a page displayed in a HTMLViewer? I understand that the HTMLViewer IS just a viewer, and that I need to use HTMLSocket to retrieve the file linked, but how do we trap the clicked link and then pass the actual link of the linked file to the HTTPSocket?

Is there an example anywhere?

CancelLoad perhaps?

There is the CancelLoad event.

This is the event where you can intercept click, check URL and the cancel the load and do something else with it.

Okay - still not clear, but I think I have it -

Get the URL for the file in the CancelLoad event and Return True
Create a new URLConnection
Pass the file name to a URLConnection
Create a folderitem to receive the file
Use the URLConnection’s Send method passing the “GET” key, the URL, and the folderitem to save the downloaded file into.

Does that seem right?

Yup!

Ummm, nope …

Even though the links in the page point to the linked file, the URL trapped by CancelClose is always the page.

For example, the link is “http://www.tolisgroup.com/downloads/argestbackup/theupdatefile.zip

I click the link, and break in the entry to CancelClose. URL is “http://www.tolisgroup.com/download.html

Where should I find the actual link URL instead of the page URL?

I’ve taken the WEBViewer out of my project and created a standalone app. I’m not receiving the linked file URL in the CancelClose event. Have I missed something? Bug? Here’s the slimmed down project if someone who understands this can take a look.

Web Download Failure Example

Tim, i tried the example and it seems to me that it works just fine, i tested the download of 3 files and all 3 were perfectly downloaded:
ArGest_Backup_4.0.0.235_Windows-x86_64_Setup.exe : 17,540,938 bytes
readme.rtf : 5507 bytes
tolis_tape_tools_manual_01-10-08.pdf : 305064 bytes

I have no idea what the problem could be. Sorry to be not as helpful as i wanted.

BTW this was on Windows 10 pro (Dutch version)

Hi Andre, Thanks! What version of Xojo were you using? I’m seeing the failure with 19r2.1 and 19r1.1.

EDIT - I just found that it works on Windows, as well. I’ll double-check Linux, but macOS definitely doesn’t work.

It’s working here. 2019r1.1 and macOS 10.14.6
Tim, what is your macOS version?

I’ve confirmed the downloaded zip decompresses. Inside is a disk image It all looks good on this end!

Running 10.13.6 and 10.15.2 for my tests.

I also just realized this got posted under “Add-Ons”; should have been General. Oh well.

Tim, does the tag have the _target=xxx field set? If so, then you might need to trap https://documentation.xojo.com/api/deprecated/htmlviewer.html#htmlviewer-newwindow in addition to CancelLoad, because the _target= property of the URL will cause the browser to try to open the link in a new window.

Hi Michael,

No _target= set.

HOWEVER … the issue appears on Linux, not macOS or Windows. Apparently I was running the Linux test in a VM on my macOS box and botched my own testing.

So, I’ve updated the subject and am looking into an alternative for Linux. This may be why I started this in Add-Ons - I was assuming that I would need to find a plugin solution.

Looks like I need:

#if TargetLinux ShowURL("http://www.tolisgroup.com/demos62051.html") #else WUpdateDownload.ShowModalWithin(WMain) #endif

Well that’s not what you’d said when I went to test this! :stuck_out_tongue:

I used Xojo 2019r2.1

It’s amazing how Coherence makes things look native under Parallels! :smiley:

Ah I understand what your post meant now. That’s kind of cool that it’s that well blended!

@Christian Schmitz has wrapped up web viewers for macOS and Windows. Perhaps it might be worth seeing if he’s got any time to help wrap up something on Linux, as this is kind of a medium-sized issue!

First file a feedback case, so I can read about it.
Include sample project. Then let’s ask @William Yu to take a look and see if there is an easy to fix bug in Xojo passing wrong URL…

Really not something that Xojo needs to worry about on my account since it’ll never make it back to 19r1.1 and anything newer is a moot point for me, but here it is if you can do something, Christian.

<https://xojo.com/issue/58928>