上传文件的改进,vaadin

时间:2014-07-19 18:05:23

标签: vaadin

我想将文件上传到git而不保存在本地磁盘上。我在我的webapp中使用vaadin + java,并从vaadin上传组件。

public OutputStream receiveUpload(String filename, String MIMEType)
{
    this.filename = filename;

    FileOutputStream fos = null;
    try {
        // exist any possibility to no saving file in filepath (only push
        // to git)
        fos = new FileOutputStream(new File(
                filepath + File.separator + filename));
    } catch (Exception e) {
        // How to omit it, I don't want to save file in filepath...
        return null;
    }

    return fos;
}

public void uploadSucceeded(Upload.SucceededEvent event)
{               
    try {
        // this method read file from filepath. Exist any possibilty to
        // transfer file from upload panel to here without saving this
        // file in filepath ?
        commitToGit(filepath + File.separator + filename);
    } catch(Exception e) {
        e.printStackTrace();
    } finally {
        // removing file from filepath, it is no comfortable for me
        File file = new File(filepath + File.separator + filename);
        if (file != null) {
            file.delete();
        }      
    }  
}

1 个答案:

答案 0 :(得分:0)

在这里查看管道功能

Best way to Pipe InputStream to OutputStream

在receiveUpload方法中,您可以在上传文件和git连接器之间设置管道。 然后不需要uploadSucceeded方法,也可以用它来清理资源。