简体   繁体   中英

Vaadin upload component receiveUpload() method

I want to upload a recorded file in vaadin. I am using the upload component of vaadin. But the problem is that I dont want to show the file dialog, rather I would like to fire events to upload component from my own buttons. I have written a class which is extended by Upload component and called its fireUploadSuccess() method, this event is successfully fired. But I want to invoke the receiveUpload() method manually, I mean by firing some event from my own button to invoke this method. Any solution friends ? Thanks!

Normally, in the base Upload Class, when the fireUploadSuccess() is called, the uploadSucceeded method of the attached class is normally called.

If you really changed the method, you maybe forgot the super() statement ?

Could you also please show us an example of your modified class if you can

here is a process that i used.

i created a custom class named MyFileReceive which implements Receiver interface of Upload.java file. There i override the method receiveUpload() and did what i want to do when uploaded file is received. Put the instance of MyFileReceiver class into the constructor of Upload class. Hope it will work..

    public class MyUI extends UI{
       private MyUI.MyFileReceiver receiver = new MyUI.MyFileReceiver();
       private Upload upload;
       protected void init(VaadinRequest vaadinRequest) {
            .............
            .......................
            upload = new Upload(null, receiver);
            upload.addSucceededListener((SucceededEvent event) -> {
            //Do what you want to do
    });
    public class MyReceiver implements Receiver {
        @Override
        public OutputStream receiveUpload(String filename, String mimeType) {
        //do what you want to do when receive upload
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM