Web File Download Question

In the docs: http://documentation.xojo.com/index.php/WebFile.Open documentation suggests that you should use the app class rather than the session class to store the WebFile in forcing the download . Why is the App a better place?

Because that way you are sure the webfile will not die before the download has ended.

If you’re talking small files the session is fine. It’s the Gigabyte sized files that really need to stick around.

Let’s clarify that. The reason for declaring a property somewhere outside of a method is so the object sticks around long enough for the browser to request it.

The location of the property has more to do with how many sessions need to be able to access it. If you create a WebFile for a particular session, making it a property of a session is just fine. On the other hand, if the file were something common to all sessions (like a logo) you might want to store that somewhere more globally, like the App class or a module.

Just remember that WebFiles have a Session property which determines whether nor not they belong to a particular session. If you create a WebFile from within a session, it belongs to that session unless you set that property to Nil. If you create a WebFile outside of a WebSession, WebFile.Session will start out Nil, and you can always set it to associate it with a session if necessary.

One last point — in 2014r3, we fixed a bug which prevented using WebFiles from within HandleSpecialUrl and HandleURL. Now if you need access to them there, just make sure the Session property is nil and you’re all set.

I have used a WebFile in a recent web service within HandleURL, and it works flawlessly.