Java 保存时上传?

Java 保存时上传?,java,frameworks,vaadin,vaadin7,Java,Frameworks,Vaadin,Vaadin7,我正在尝试一种保存图片的方法,当我使用vaadin7的上传组件点击保存按钮时。 上传组件有一个发送图像的按钮,但我想在我用我定义的名称单击窗口的“保存”按钮时保存该按钮 我正在试这个 //upload image Upload upload = new Upload("Choose your picture"); upload.setButtonCaption(null); mainLayout.addComponent(upload); Button btnSave = new But

我正在尝试一种保存图片的方法,当我使用vaadin7的上传组件点击保存按钮时。 上传组件有一个发送图像的按钮,但我想在我用我定义的名称单击窗口的“保存”按钮时保存该按钮

我正在试这个

//upload image   
Upload upload = new Upload("Choose your picture");
upload.setButtonCaption(null);
mainLayout.addComponent(upload);

Button btnSave = new Button("Save");
btnSave.addClickListener(new Button.ClickListener() {
    @Override
    public void buttonClick(ClickEvent event) {
        //click to save all fields and picture choosed in upload

    }
});


/** upload image picture */
public class ImageUpload implements Receiver{
    private File file;
    private String cpf; // image's name example 222.333.444-55

    /** save image picture */
    @Override
    public OutputStream receiveUpload(String filename, String mimeType) {       
        FileOutputStream fos = null;        
        try{
            if(new File(filename).getName().endsWith("jpg")){
                String cpfFormato = this.cpf.replaceAll("\\.", "").replace("-", "");
                String[] imagem = filename.split("\\.");
                String novaImagem = cpfFormato + ".jpg"; //22233344455.jpg
                file = new File(novaImagem);
                fos = new FileOutputStream("/tmp/" + file);             
            }else{
                new Notification("Erro de arquivo \n",
                             "Only jpg", 
                              Notification.Type.ERROR_MESSAGE)
                             .show(Page.getCurrent());
            }           
        }catch(FileNotFoundException ex){
            new Notification("File not found \n", 
                              ex.getLocalizedMessage(), 
                              Notification.Type.ERROR_MESSAGE)
                              .show(Page.getCurrent());
            return null;
        }
        return fos;
    }   

}

有什么想法吗?

使用
upload.submitUpload()方法

提示:正如您在API描述中看到的,您可以通过设置
upload.setButtonCaption(null)来隐藏upload internal submit按钮

链接到API: