Forcing a download

Syntax help please!

f=WebFile.Open(MyFolderItem) f.ForceDownload=True ShowURL f.url //<---Debugger telling me: This item does not exist "ShowURL"

f and MyFolderItem are defined.

[quote=181274:@Jay Menna]Syntax help please!

f=WebFile.Open(MyFolderItem) f.ForceDownload=True ShowURL f.url //<---Debugger telling me: This item does not exist "ShowURL"

f and MyFolderItem are defined.[/quote]

Look at the download example. The proper code is in there.

[quote=181274:@Jay Menna]Syntax help please!

f=WebFile.Open(MyFolderItem) f.ForceDownload=True ShowURL f.url //<---Debugger telling me: This item does not exist "ShowURL"

f and MyFolderItem are defined.[/quote]
Where is this code running from? ShowUrl is a method of Session because it needs to be sent to a specific browser.

Thanks Greg and Michel.

Greg:
We have a “Catalog” of static PDF documents that get forced dowloaded to customers. They all live in a folder called “Catalog”

What we wanted was a generic method

Force_CatalogDoc(“NameofPDF”) method where we could quickly just force the document down

We created the method in a Module (called UtilityMethods)

Just call one line: UtilityMethods.Force_CatalogDoc(“myPDf.pdf”)

Turns out the compiler does not see ShowURL inside a module.

Michel:
You think I should google it too?

[quote=181774:@Jay Menna]Michel:
You think I should google it too?[/quote]

Simply look in the Examples Projects folder, next to the Xojo executable. You will find the Downloading project inside the Web folder. I have been using a slightly modified version of that project for years to deliver my software.

Please note two things:

  1. if you want to download PDF files then set myDownloadFile.UseCompression = False as PDF files are already compresses
  2. if you want to download TXT files on Windows or Linux (Mac is OK) then myDownloadFile.ForceDownload = True has no effect and the files are shown in the browser window, so you need to zip the TXT files first.

David: Thanks. Very useful information.

Regarding myDownloadFile.UseCompression=False, It makes sense. Ill certainly do that.

Im curious if that failure to do so will result in unnecessary / redundant compression or will it cause the recipient browser to balk or how an error. I would test it myself but I have only so many browsers.

Depends on how you generate the PDF but in general that is a good point.

Nope, just adds work for the server for no benefit since it will not reduce the bandwidth used any further at that point.

If you want a generic centralized method, just make sure you pass in the session object so you can call aSession.ShowURL.

I was generating 100 page PDF files, but it was taking over a minute before the browser would start to download them, whilst other files would download instantly. If you only have small PDF files then the difference may be imperceivable, but I would turn off compression anyway since it’s easy to do.