UploadFileHandler from Matti

Hi @Matti

Well, I’m writing to you directly because I understand that you’re the developer of this class, from Viritin itself, hehe…

I just have this here.

When I upload an .mp4 file, which I have as an unsupported file, it jumps to the catch

but when that exception is triggered, the

return new UploadFileHandler((InputStream inputStream, UploadFileHandler.FileDetails metadata) -> {
            try (final FastByteArrayOutputStream fastOutputStream = new FastByteArrayOutputStream()) {
                if (SupportFilesEnum.fromExtension(FileUtils.getFileExtension(metadata.fileName())) == SupportFilesEnum.UNKNOWN) {
                    throw new IllegalArgumentException("File not supported!");
                }
                String fileName = metadata.fileName();
                if (this.decompressionService.isCompressedFile(fileName)) {
                    List<DecompressedFile> files = this.decompressionService.decompressFile(fileName, inputStream);
                    files.forEach(decompressedFile -> {
                        this.executeUI(() -> this.processFile(metadata, decompressedFile.content(), true, decompressedFile));
                    });
                } else {
                    inputStream.transferTo(fastOutputStream);
                    byte[] bytes = fastOutputStream.toByteArray();
                    this.executeUI(() -> {
                        this.processFile(metadata, bytes, false, new DecompressedFile(null, null, 0L));
                    });
                }
                return () -> {
                    this.uploader.clearFileList();
                    this.searchPopover.updateItems(this.getXsdXmlFiles());
                };
            } catch (Exception error) {
                return () -> {
                    log.error("Error catch uploader: {}", error.getMessage());
                    Notification.show("Upload failed: " + error.getMessage(),
                                    2000, Notification.Position.MIDDLE)
                            .addThemeVariants(NotificationVariant.LUMO_WARNING);
                    this.uploader.clearFileList();
                };
            }
        })
                .withClearAutomatically(true)
                .withAddedClassName("upload-xml-xsd", LumoUtility.Padding.XSMALL, LumoUtility.Width.FULL,
                        LumoUtility.Margin.Right.MEDIUM, LumoUtility.Margin.Left.NONE)
                .withDragAndDrop(true)
                .withDropLabelIcon(new Span())
                .withDropLabel(new Span("Drop files here, only support: " + XsdValidatorConstants.SUPPORT_FILES))
                .withUploadButton(attachment);
Notification.show(“Upload failed: ” + error.getMessage(),
                                    2000, Notification.Position.MIDDLE)
                            .addThemeVariants(NotificationVariant.LUMO_WARNING);

It notifies approximately 6 times.

2026-01-29T19:23:05.705+01:00 ERROR 2284174 --- [nio-8888-exec-4] com.rubn.xsdvalidator.view.Input         : Error catch uploader: File not supported!
2026-01-29T19:23:06.245+01:00 ERROR 2284174 --- [nio-8888-exec-7] com.rubn.xsdvalidator.view.Input         : Error catch uploader: File not supported!
2026-01-29T19:23:06.440+01:00 ERROR 2284174 --- [nio-8888-exec-9] com.rubn.xsdvalidator.view.Input         : Error catch uploader: File not supported!
2026-01-29T19:23:06.568+01:00 ERROR 2284174 --- [nio-8888-exec-3] com.rubn.xsdvalidator.view.Input         : Error catch uploader: File not supported!
2026-01-29T19:23:06.727+01:00 ERROR 2284174 --- [nio-8888-exec-8] com.rubn.xsdvalidator.view.Input         : Error catch uploader: File not supported!
2026-01-29T19:23:07.028+01:00 ERROR 2284174 --- [nio-8888-exec-5] com.rubn.xsdvalidator.view.Input         : Error catch uploader: File not supported!

Sounds like a problem with server-side declining and the large file junking. Probably quite easy to fix, client side should check the error code (and server should set it to something else if not set already). Can you file an issue to the repo?

thanks,

ready: server-side declining and the large file junking, with UploadFileHandler ? · Issue #100 · viritin/flow-viritin · GitHub

Looks like a similar or the same issue as UploadHandler.handleUploadRequest called multiple times after throwing exception · Issue #23186 · vaadin/flow · GitHub

Might be related in a sense that same exception seems to be printed out to the log multiple times in some case, but there was an issue in exception handling in the UploadFileHandler callback (the exception that was supposed to signal error was eaten), which didn’t properly send 500 response to the client.

1 Like