File Upload and Download"
From Documentation
(Created page with "{{ZKDevelopersReferencePageHeader}} =Version History= {{LastUpdated}} {| border='1px' | width="100%" ! Version !! Date !! Content |- | | | |} {{ZKDeveloper...") |
|||
Line 1: | Line 1: | ||
{{ZKDevelopersReferencePageHeader}} | {{ZKDevelopersReferencePageHeader}} | ||
+ | =File Upload= | ||
+ | You could associate the upload feature to a component, such as <javadoc>org.zkoss.zul.Button</javadoc>, <javadoc>org.zkoss.zul.Toolbarbutton</javadoc> or <javadoc>org.zkoss.zul.Menuitem</javadoc>. In other words, you could make a button or a menu item to upload a file when the user clicks on it. | ||
+ | |||
+ | The implementation is straightaway: | ||
+ | |||
+ | #Assign the <tt>upload</tt> attribute to true for the component used to upload a file | ||
+ | #Assign an event listener to the component for the <tt>onUpload</tt> event | ||
+ | |||
+ | For example, | ||
+ | |||
+ | <source lang="xml"> | ||
+ | <zk> | ||
+ | <zscript> | ||
+ | void upload(UploadEvent event) { | ||
+ | org.zkoss.util.media.Media media = event.getMedia(); | ||
+ | if (media instanceof org.zkoss.image.Image) { | ||
+ | org.zkoss.zul.Image image = new org.zkoss.zul.Image(); | ||
+ | image.setContent( (org.zkoss.image.Image) media); | ||
+ | image.setParent(pics); | ||
+ | } else { | ||
+ | Messagebox.show("Not an image: "+media, "Error", Messagebox.OK, Messagebox.ERROR); | ||
+ | } | ||
+ | } | ||
+ | </zscript> | ||
+ | <button label="Upload" upload="true" onUpload="upload(event)"/> | ||
+ | <vlayout id="pics" /> | ||
+ | </zk> | ||
+ | </source> | ||
+ | |||
+ | You could control the maximal allowed number of files, the maximal allowed size and other information by use of <javadoc method="setUpload(java.lang.String)">org.zkoss.zul.Button</javadoc>. | ||
+ | |||
+ | <source lang="xml"> | ||
+ | <menupopup> | ||
+ | <menuitem label="Upload" upload="true,maxsize=-1,native"/> | ||
+ | </menupopup> | ||
+ | </source> | ||
+ | |||
+ | =File Download= | ||
=Version History= | =Version History= | ||
{{LastUpdated}} | {{LastUpdated}} |
Revision as of 10:26, 13 October 2011
File Upload
You could associate the upload feature to a component, such as Button, Toolbarbutton or Menuitem. In other words, you could make a button or a menu item to upload a file when the user clicks on it.
The implementation is straightaway:
- Assign the upload attribute to true for the component used to upload a file
- Assign an event listener to the component for the onUpload event
For example,
<zk>
<zscript>
void upload(UploadEvent event) {
org.zkoss.util.media.Media media = event.getMedia();
if (media instanceof org.zkoss.image.Image) {
org.zkoss.zul.Image image = new org.zkoss.zul.Image();
image.setContent( (org.zkoss.image.Image) media);
image.setParent(pics);
} else {
Messagebox.show("Not an image: "+media, "Error", Messagebox.OK, Messagebox.ERROR);
}
}
</zscript>
<button label="Upload" upload="true" onUpload="upload(event)"/>
<vlayout id="pics" />
</zk>
You could control the maximal allowed number of files, the maximal allowed size and other information by use of Button.setUpload(String).
<menupopup>
<menuitem label="Upload" upload="true,maxsize=-1,native"/>
</menupopup>
File Download
Version History
Version | Date | Content |
---|---|---|