我想上傳文件到git而不保存在本地磁盤上。我在我的webapp中使用vaadin + java,並從vaadin上傳組件。上傳文件的改進,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();
}
}
}
您的commitToGit方法必須只提供一個InputStream,您可以將上傳組件的OutputStream管道傳遞給git上傳器的InputStream。 –
您能否提供代碼示例...?我不知道它是如何到達的...... – user3328186