ZATS UploadAgent"
From Documentation
Line 31: | Line 31: | ||
* '''Line 13''': Cast component to <tt>UploadAgent</tt> and keep its reference. | * '''Line 13''': Cast component to <tt>UploadAgent</tt> and keep its reference. | ||
* '''Line 14''': Invoke <tt>upload()</tt> method to upload a file. We can specify content type through the second argument and '''null''' value indicates binary form (application/octet-stream). | * '''Line 14''': Invoke <tt>upload()</tt> method to upload a file. We can specify content type through the second argument and '''null''' value indicates binary form (application/octet-stream). | ||
− | * '''Line 15''': | + | * '''Line 15''': Don't forget to invoke <tt>finish()</tt>method when the uploading is done. Notice that the instance of <tt>UploadAgent</tt> should be the same one. |
− | * '''Line 16''': | + | * '''Line 16''': It specifies the content of file is a plain text. |
− | * '''Line 19, 21''': | + | * '''Line 19, 21''': The <tt>upload(String, InputStream, String)</tt> method won't close the input stream, we should close it manually. |
'''Notes''' | '''Notes''' |
Revision as of 07:18, 29 June 2012
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:
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();
}
- Line 13: Cast component to UploadAgent and keep its reference.
- Line 14: Invoke upload() method to upload a file. We can specify content type through the second argument and null value indicates binary form (application/octet-stream).
- Line 15: Don't forget to invoke finish()method when the uploading is done. Notice that the instance of UploadAgent should be the same one.
- Line 16: It specifies the content of file is a plain text.
- Line 19, 21: The upload(String, InputStream, String) method won't close the input stream, we should close it manually.
Notes
- ↑ for more detail, please refer to ZK Developer's Reference/UI Patterns/File Upload and Download and ZK Component Reference/Essential Components/Fileupload
Upload Files with the Static Method
Supported Components
DesktopAgent | 5, 6 |