0

I want to upload file to git without saving on local disk. I use vaadin + java in my webapp, and upload component from 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();
        }      
    }  
}
Chris Martin
  • 30,334
  • 10
  • 78
  • 137

1 Answers1

0

Look here for the pipe functionality

Best way to Pipe InputStream to OutputStream

in the receiveUpload method you setup the pipe between the uploading file and your git connector. The uploadSucceeded method is then not needed or can be used to cleanup resources.

Community
  • 1
  • 1
André Schild
  • 4,592
  • 5
  • 28
  • 42
  • hmm...Probably I need conversio inn other side. I have (fos) FileOutpuTStream, the first method in method commitToGit() looks: private byte[] readStreamToByteArray(InputStream stream) - so I need inputStrea, not OutputStream... – user3328186 Jul 21 '14 at 06:39