Filedownload"

From Documentation
Line 32: Line 32:
  
 
== The Resumable Download ==
 
== The Resumable Download ==
 +
 +
{{ZK EE}}
  
 
In certain situations, you might prefer to generate an URL that can be used even if the desktop becomes invalid. For example, you want to allow users to use a download manager (such as <code>wget</code> and <code>DownThemAll</code>). Another example is related to the blocking feature found in some browsers -- which confirm the download with the user and causes the page to reload (and then the previous desktop is lost).
 
In certain situations, you might prefer to generate an URL that can be used even if the desktop becomes invalid. For example, you want to allow users to use a download manager (such as <code>wget</code> and <code>DownThemAll</code>). Another example is related to the blocking feature found in some browsers -- which confirm the download with the user and causes the page to reload (and then the previous desktop is lost).
Line 37: Line 39:
 
To solve this, you have to use the so-called resumable download. By resumable we mean the user can bookmark the URL and download it later (and even resume the download in the middle). On the other hand, the download URL of the <code>save</code> method becomes obsolete as soon as the desktop (or session) is gone.
 
To solve this, you have to use the so-called resumable download. By resumable we mean the user can bookmark the URL and download it later (and even resume the download in the middle). On the other hand, the download URL of the <code>save</code> method becomes obsolete as soon as the desktop (or session) is gone.
  
To use resumable download, you have to invoke the <code>saveResumable</code> method of the <code>org.zkoss.zkmax.zul.Filedownload</code> class (available in the Enterprise edition) instead of <code>save</code> as depicted below:
+
To use resumable download, you have to invoke the <code>saveResumable</code> method of <javadoc>org.zkoss.zkmax.zul.Filedownload</javadoc> instead of <code>save</code> as depicted below:
  
 
<source lang="xml">
 
<source lang="xml">
Line 58: Line 60:
 
(( Default: 4096.
 
(( Default: 4096.
  
If you want more advanced control, you can implement {@link FiledownloadListener} and specify it in a library property called <code>org.zkoss.zkmax.zul.FiledownloadListener.class</code>. For examle, in <code>zk.xml</code>, you can do:
+
If you want more advanced control, you can implement <javadoc>org.zkoss.zkmax.zul.FiledownloadListener</javadoc> and specify it in a library property called <code>org.zkoss.zkmax.zul.FiledownloadListener.class</code>. For examle, in <code>zk.xml</code>, you can do:
  
 
<source lang="javascript">
 
<source lang="javascript">

Revision as of 09:19, 18 January 2011

Fileupload

Employment/Purpose

Filedownload provides provides a set of utilities to prompt a user for downloading a file from the server to the client.

Notice that Filedownload is not a component. Rather, it is a collection of utilities for file download.

Unlike the iframe component that displays the file in the browser window, a file download dialog is shown at the browser if one of the save methods is called. Then, the user can specify the location in his local file system to save the file.

10000000000002AF000001BB582C2DD7.png

<button label="Download download.html">
	<attribute name="onClick">{
		java.io.InputStream is = desktop.getWebApp().getResourceAsStream("/test/download.html");
		if (is != null)
			Filedownload.save(is, "text/html", "download.html");
		else
			alert("/test/download.html not found");
	}
	</attribute>
</button>

The Resumable Download

  • Available for ZK:
  • http://www.zkoss.org/product/zkhttp://www.zkoss.org/whyzk/zkeeVersion ee.png

In certain situations, you might prefer to generate an URL that can be used even if the desktop becomes invalid. For example, you want to allow users to use a download manager (such as wget and DownThemAll). Another example is related to the blocking feature found in some browsers -- which confirm the download with the user and causes the page to reload (and then the previous desktop is lost).

To solve this, you have to use the so-called resumable download. By resumable we mean the user can bookmark the URL and download it later (and even resume the download in the middle). On the other hand, the download URL of the save method becomes obsolete as soon as the desktop (or session) is gone.

To use resumable download, you have to invoke the saveResumable method of Filedownload instead of save as depicted below:

<window title="Save Resumable" border="normal">
	<button label="download"
	onClick='Filedownload.saveResumable("foo.txt", "text/plain", null)'/>
</window>

Then, the URL generated by saveResumable can be copied to the download manager the user prefers.

Control Resumable Download

Since the resumable download can be used in any session or without any session, or with a different client (such flashget), you might want to limit the download under certain condition. There are two library properties that can control the number of allowed resumable downloads.

  • org.zkoss.zk.download.resumable.lifetime
    • Specifies when the download URL will be expired (unit: second).
    • Default: 14400 (i.e., 4 hours).
  • org.zkoss.zk.download.resumable.maxsize
    • Specifies the maximal allowed number of resumable downloads.

(( Default: 4096.

If you want more advanced control, you can implement FiledownloadListener and specify it in a library property called org.zkoss.zkmax.zul.FiledownloadListener.class. For examle, in zk.xml, you can do:

<library-property>
  <name>org.zkoss.zkmax.zul.FiledownloadListener.class</name>
  <value>com.foo.MyDownloadListener</value>
</library-property>

Version History

Last Update : 2011/01/18


Version Date Content
     



Last Update : 2011/01/18

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.