Upload Component using FileBuffer receiver


Is there an example using the FileBuffer receiver for the upload component? I see mostly MemoryBuffer and MultiFileMemoryBuffer but can’t locate an example using FileBuffer.


The answer really depends on your use-case. The FileBuffer generally stores the file uploaded somewhere into the temp folder, then allows you to read the file contents e.g. when you’re storing the file into the database:

public class MainView extends VerticalLayout {

    public MainView() {
        final FileBuffer fileBuffer = new FileBuffer();
        final Upload upload = new Upload(fileBuffer);
        upload.addAllFinishedListener(e -> {
            System.out.println("File uploaded: " + fileBuffer.getFileName());
            // now you can read the file contents (the file is stored in the temp folder) and store it into the database for example:
            // try (InputStream in = fileBuffer.getInputStream()) {
            //   ...
            // }

However, I was told that fileBuffer.getInputStream() will fail with an exception, which sounds like a bug to me. Let me investigate please.

Here’s an open ticket about the issue: https://github.com/vaadin/vaadin-upload/issues/334 - looks like it’s prioritized, so it should be fixed soon.

Yes, that was the error I was receiving but wasn’t sure it was a bug. Thank you for looking into it.