ZK 5.0.6アップロード
----------ZK 5.0.6アップロード、upload----------
zulページ
Javaコード
リスナーを使用する場合:
zulページ
<button label=" " id="btnUpload" upload="true,maxsize=-1,native"
onUpload="win$composer.upload(event.media)"/>
Javaコード
public String upload(Media media) throws IOException {
String suffix = media.getName().substring(media.getName().lastIndexOf("."));
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
picSrc = picPath +"/"+sdf.format(new Date())+suffix;
InputStream ins = media.getStreamData();
File f = new File(Executions.getCurrent().getDesktop().
getWebApp().getRealPath(picPath)+"/"
+sdf.format(new Date())+suffix);
if (!f.exists()) {
f.createNewFile();
}
OutputStream out = new FileOutputStream(f);
byte[] buf = new byte[1024];
int len;
while ((len = ins.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.close();
ins.close();
return picSrc;
}
リスナーを使用する場合:
final Button uploadPic = new Button(" ");
uploadPic.setUpload("true,maxsize=-1,native");
uploadPic.addEventListener(Events.ON_UPLOAD, new EventListener(){
@Override
public void onEvent(Event event) throws Exception {
Media media = ((UploadEvent)event).getMedia();
info.setPicSrc(upload(media));//upload
}
});