Vaadin version: 13.0.7
Hey everyone,
I am using the upload component. However when I try to access the inputstream of the FileBuffer or MultiFileBuffer it says stream closed. When I use the MemoryBuffer or it’s multi counterpart it works. I prefer to use FileBuffer because I don’t want to have the documents in memory of the application. Does anyone know what is causing this?
example code:
var:
private FileBuffer foodArticlesReceiver = new FileBuffer();
in the init method:
foodArticleUpload.setReceiver(foodArticlesReceiver);
foodArticleUpload.setMaxFileSize(10 * 1024 * 1024);
foodArticleUpload.setAcceptedFileTypes(allowedFileTypes.EXCELFILENAMEEXTENSIONS);
foodArticleUpload.setMaxFiles(1);
foodArticleUpload.addFinishedListener(e -> enableUploadButton(e,foodArticlesReceiver));
when the upload is finished:
note: This method is only used by me to test functionality. That’s why the names can be abit wacky.
private void enableUploadButton(FinishedEvent e, FileBuffer f){
try (InputStream inputStream = f.getInputStream()){
File targetFile = new File("src/main/resources/targetFile.xlxs");
FileUtils.copyInputStreamToFile(inputStream, targetFile);
} catch (IOException ex) {
Logger.getLogger(ArticleUploadComponent.class.getName()).log(Level.SEVERE, null, ex);
}
}