ondownloaded is deprecated

I’m getting the warning message “ondownloaded is deprecated”.

I’m using ondownloaded to point to AddressOf a method used to clear the webfile property once the file has been downloaded, as recommended in the documentation: http://documentation.xojo.com/index.php/WebFile.OnDownloaded

What replaces “ondownloaded”?

The Downloaded event.

According to the docs, Downloaded tells me when the download starts, not when it has finished.

http://documentation.xojo.com/index.php/WebFile.Downloaded

Confused.

Unless someone knows something I don’t (which certainly happens), I’m not sure if you can tell when someone has finished downloading a file. By that point the client browser is downloading the file directly from the server. “Downloaded”, therefore means when the file has been requested to be downloaded. This is in the same way that a “visited” link just means it was used, whether or not page finished downloading or not.

Jason is correct. Both the old delegate and the new event handler are called after the browser has finished handing off the download. There is no mechanism to know when the actual download has completed on the local computer.

Aha, thanks guys. Could the documentation be updated, please? Instead of saying “When the download is completed”, it should say “When the client browser has started the download”.

http://documentation.xojo.com/index.php/WebFile.OnDownloaded

So, this must mean that setting the Webfile to Nil when the client begins the download (i.e., the Ondownloaded event fires) does not affect the rest of the download.

Could someone give me some example code how to use the Downloaded event, please? I have a Session property that is a WebFile, but I don’t know where to find the Downloaded event. The Xojo file download example still uses the OnDownloaded property to point to the appropriate method using a weak reference.

I’ll get that updated. Essentially, you’ll want to subclass WebFile to see the Downloaded event or use AddHandler to map the Downloaded event to a method on your page or session.

In my WEB project I get a “list” of files available for download. Then I put them in a weblistbox. The user can select one or MORE rows and then click “download” – I want all the selected files to download. It seems like you can’t just Loop through the listbox and request each one …even though I attached an array of web files to my main window.
So…When they click download I call a sub that seeks out and only requests the FIRST selected file…and I used an add handler to map the downloaded event which increments the listbox row and calls the subroutine to seek-out and download the next selected file setting the same add handler for the corresponding web file array element.
How SHOULD I be doing this? Downloading ONE file…no problem…downloading a selected list of Files is proving problematic. Any suggestions are always appreciated.

I found that for some reason…my application running in debug would “quit” for no apparent reason when downloading a larger file. I finally “gave up” trying to solve the problem and built the application to see if it would behave similarly as a stand alone web application. I stress tested it by downloading dozens of small files in rapid succession with no issues. I downloaded a file of over 700 MB with no issue. While that was downloading I downloaded some additional files in another session with no problems. Although I was using the 64K chunk method…there was a moment when the entire application was non-resonsive on the large 700MB file…but ultimately… it returned to responsiveness relatively quickly. I can see where downloading large files “in debug mode” must exceed some limitation. I would have expected some kind of “error” message. No matter I suppose.

Can someone confirm this? I use to store the file in an downloads array on the session and on the OnDownloaded event I would remove the file from the session’s downloads array so it would go out of scope and memory.

If I remove the OnDownloaded delegate and instead put this logic in the WebFile.Downloaded event, will it still work properly?

Essenitally if I turn this session method:

Sub DownloadFile(file as WebFile) Downloads.Append(file) file.OnDownloaded = WeakAddressOf FileDownloaded showurl(file.url) End Sub
into:

Sub DownloadFile(file as WebFile) Downloads.Append(file) AddHandler file.Download WeakAddressOf FileDownloaded showurl(file.url) End Sub

And the FileDownloaded method is:

Sub FileDownloaded(file as WebFile) downloads.Remove(Downloads.IndexOf(file)) file = nil Exception End Sub

Then it should function the same as before and I wont have a memory leak?

[quote=186912:@Brock Nash]Essenitally if I turn this session method:

Sub DownloadFile(file as WebFile) Downloads.Append(file) file.OnDownloaded = WeakAddressOf FileDownloaded showurl(file.url) End Sub
into:

Sub DownloadFile(file as WebFile) Downloads.Append(file) AddHandler file.Download WeakAddressOf FileDownloaded showurl(file.url) End Sub

And the FileDownloaded method is:

Sub FileDownloaded(file as WebFile) downloads.Remove(Downloads.IndexOf(file)) file = nil Exception End Sub

Then it should function the same as before and I wont have a memory leak?[/quote]
make sure you also call RemoveHandler in the FileDownloaded method.

But if its a weak address why do I have to use RemoveHandler? Shouldn’t the object going out of scope clean up all of this?

And if I do AddHandler with a WeakAddress do I need to do RemoveHandler with a WeakAddress?

This is what I have currently:

Sub DownloadFile(file as WebFile) Downloads.Append(file) AddHandler file.Downloaded, WeakAddressOf FileDownloaded showurl(file.url) End Sub

Sub FileDownloaded(file as WebFile) downloads.Remove(Downloads.IndexOf(file)) RemoveHandler file.Downloaded, WeakAddressOf FileDownloaded file = nil Exception End Sub