1
我希望一次MultiFileUpload在Vaadin - 我想要做一些任务时最后一个文件被上传
- 上传多个文件做两个任务。
- 当所有选定的文件上传后,我想打开一个窗口,并选择他们的类型和其他一些工作,然后保存它。
当我这样做是为了单个上传它工作正常。
现在我试图与MultiFileUpload addon实现multiupload但是事件public void handleFile(InputStream in, String filename, String mimetype, long length)
是逐一触发每个文件。我想在最后一个文件上传时打开窗口。我如何检测最后一个文件是上传的?
这里是我的代码:
protected void init(VaadinRequest vaadinRequest) {
FormLayout layout = new FormLayout();
UploadFinishedHandler uploadFinishedHandler = new UploadFinishedHandler() {
@Override
public void handleFile(InputStream in, String filename, String mimetype, long length) {
try {
FileOutputStream fos = null;
String filePath = "/home/yassir/Desktop/";
File dirFile = new File(filePath);
if (!dirFile.exists()) {
dirFile.mkdirs();
}
filePath += filename;
Button btn = new Button(filename);
layout.addComponent(btn);
File file = new File(filePath);
fos = new FileOutputStream(file);
byte[] buffer = new byte[in.available()];
in.read(buffer);
fos.write(buffer);
fos.close();
} catch (FileNotFoundException ex) {
Logger.getLogger(MyUI.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(MyUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
};
UploadStateWindow uploadStateWindow = new UploadStateWindow();
MultiFileUpload multiFileUpload = new MultiFileUpload(uploadFinishedHandler, uploadStateWindow);
layout.addComponent(multiFileUpload);
setContent(layout);
}
我会调用该函数createWindowType()
(我这里没加)。
是的。你是对的。非常感谢。 –