ZATS UploadAgent"

From Documentation
Line 3: Line 3:
 
__TOC__
 
__TOC__
 
  Since 1.1.0
 
  Since 1.1.0
 +
 +
ZATS Mimic introduces the <tt>UploadAgent</tt> to simulate file uploading operation with consistent usage. <tt>UploadAgent</tt> supports single or multiple files uploading as ZK components do.
  
 
= Upload Files with a Component =
 
= Upload Files with a Component =
  
We usually perform file downloading through <javadoc>org.zkoss.zul.Filedownload</javadoc> when some events are triggered
+
The basic way to upload files is using a component such as <javadoc>org.zkoss.zul.Fileupload</javadoc>, <javadoc>org.zkoss.zul.Button</javadoc>, <javadoc>org.zkoss.zul.Menuitem</javadoc>, <javadoc>org.zkoss.zul.Toolbarbutton</javadoc> and so on. <ref>for more detail, please refer to [[ZK Developer's Reference/UI Patterns/File Upload and Download]] and [[ZK Component Reference/Essential Components/Fileupload]]</ref> If we assign the <tt>upload</tt> attribute to these components, users can click and select a file to upload through the browser dialog, as following image shows:
<ref>for more detail, please refer to [[ZK Developer's Reference/UI Patterns/File Upload and Download]] and [[ZK Component Reference/Essential Components/Fileupload]]</ref>
+
[[File:Zats_upload_button.png]]
 +
 
 +
We can cast these components as a <tt>UploadAgent</tt> and perform file uploading. Following is a typical example of single file uploading:
 +
 
 +
<source lang="java" start="10" high="13, 14, 15, 16, 19, 21">
 +
@Test
 +
public void test(File file) throws Exception {
 +
DesktopAgent desktop = Zats.newClient().connect("/upload.zul");
 +
UploadAgent agent = desktop.query("#btn").as(UploadAgent.class);
 +
agent.upload(file, null);
 +
agent.finish();
 +
agent.upload(file, "text/plain");
 +
agent.finish();
 +
FileInputStream is = new FileInputStream(file);
 +
agent.upload(file.getName(), is, "text/plain");
 +
agent.finish();
 +
is.close();
 +
}
 +
</source>
 +
 
  
 
'''Notes'''
 
'''Notes'''

Revision as of 10:00, 25 June 2012

WarningTriangle-32x32.png This page is under construction, so we cannot guarantee the accuracy of the content!

aowang



Since 1.1.0

ZATS Mimic introduces the UploadAgent to simulate file uploading operation with consistent usage. UploadAgent supports single or multiple files uploading as ZK components do.

Upload Files with a Component

The basic way to upload files is using a component such as Fileupload, Button, Menuitem, Toolbarbutton and so on. [1] If we assign the upload attribute to these components, users can click and select a file to upload through the browser dialog, as following image shows: Zats upload button.png

We can cast these components as a UploadAgent and perform file uploading. Following is a typical example of single file uploading:

@Test
public void test(File file) throws Exception {
	DesktopAgent desktop = Zats.newClient().connect("/upload.zul");
	UploadAgent agent = desktop.query("#btn").as(UploadAgent.class);
	agent.upload(file, null);
	agent.finish();
	agent.upload(file, "text/plain");
	agent.finish();
	FileInputStream is = new FileInputStream(file);
	agent.upload(file.getName(), is, "text/plain");
	agent.finish();
	is.close();
}


Notes

Upload Files with the Static Method

Supported Components

Components
Version
Note
DesktopAgent 5, 6


aowang




Last Update : 2012/06/25

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