-
FEATURED COMPONENTS
First time here? Check out the FAQ!
My friends,
I am trying save an uploaded file with zk component in disk, but i failed in the attempt. There is a way of do?.
I need a example i am something new with zk, I appreciate your answers
Thanks.!
you can see the demo sample from my blog:
http://corejavaexample.blogspot.in/2013/06/how-to-drop-your-file-using-dropupload.html
Index.zul
<?page title="Auto Generated index.zul"?>
<window title="Drop here" border="normal" width="100%" height="100%"
apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('com.demo.DropFileViewModel')">
<dropupload maxsize="5120" detection="none"
onUpload="@command('doUpload')">
</dropupload>
<button label="Download" onClick="@command('doDownload')"></button>
</window>
DropFileViewModel.java
package com.demo;
import org.zkoss.bind.BindContext;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.ContextParam;
import org.zkoss.bind.annotation.ContextType;
import org.zkoss.util.media.Media;
import org.zkoss.zhtml.Filedownload;
import org.zkoss.zk.ui.event.UploadEvent;
import org.zkoss.zul.Messagebox;
public class DropFileViewModel {
Media media;
@Command
public void doUpload(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx) {
UploadEvent upEvent = null;
Object objUploadEvent = ctx.getTriggerEvent();
if (objUploadEvent != null && (objUploadEvent instanceof UploadEvent)) {
upEvent = (UploadEvent) objUploadEvent;
}
if (upEvent != null) {
media = upEvent.getMedia();
Messagebox.show("File Uploaded: " + media.getName());
//you can find Byte data from media object.Then you can write as a file in local directory
}
}
@Command
public void doDownload() {
if (media != null)
Filedownload.save(media);
else
Messagebox.show("First Drop Your File");
}
}
Asked: 2014-03-22 16:31:29 +0800
Seen: 47 times
Last updated: Mar 22 '14
How to handle big (large) file upload?
Filter fileupload with parameter accept
Initialisation of components with visible attribute
Need validation for checkbox, radio, listbox
File selector window doesn't popup after clicking Upload button
Having problems with upload button in IE 10+ using ZK 5
MVVM Radio button with form binding
Below code from jo.js causes "Invalid object calling" error in IE10. Please provide solution.