0

How save file uploaded into folder local (in disk) ?

asked 2014-03-22 16:31:29 +0800

chushack gravatar image chushack
1

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.!

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2014-03-22 17:25:05 +0800

sitansu gravatar image sitansu
2254 13
http://java91.blogspot.in...

updated 2014-03-22 17:32:17 +0800

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");

    }
}
link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2014-03-22 16:31:29 +0800

Seen: 43 times

Last updated: Mar 22 '14

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More