Upload.addFinishedListener not called when file doesn't meet constraints

Hello Vaadin experts!

I have an Upload component in my UI

MemoryBuffer receiver = new MemoryBuffer();
Upload upload = new Upload(receiver);

upload.setAcceptedFileTypes("text/csv");
upload.setMaxFileSize(1024);

When I try to upload a file that’s greater than 1024 bytes. I expect the Upload.addFailedListener to be called, but it doesn’t get called. Any ideas why and how to fix?

Or better still, how can I know that the file that was attempted to be uploaded doesn’t meet the requirement so I can show the correct prompt to a user

If it helps.

<vaadin.version>13.0.11</vaadin.version> Spring Boot Version <version>2.1.6.RELEASE</version>

I guess you have the same problem as described in this bug report

https://github.com/vaadin/vaadin-upload-flow/issues/134

In case yes, the good news is that there is process ongoing to fix it.

Tatu Lund:
I guess you have the same problem as described in this bug report

https://github.com/vaadin/vaadin-upload-flow/issues/134

In case yes, the good news is that there is process ongoing to fix it.

Unfortunately it’s not the same problem.

I’m only uploading a file. As you can see I set the max file size with Upload.setMaxFileSize to 1024 bytes.

Any attempt to upload a file with more than that size fails i.e Upload.addSucceededListener isn’t called; without any prompts or feedback.

Uploading files within the constraint works

If it helps.

<vaadin.version>13.0.11</vaadin.version>
Spring Boot Version
<version>2.1.6.RELEASE</version>

This is the solution/work around

upload.getElement().addEventListener("file-reject", event -> onFileRejected(upload.getMaxFileSize(), event)); But the event JsonObject is empty which is most likely due to a bug described below

The vaadin-upload web component fires a file-reject event, when the file doesn’t meet specified constraints https://vaadin.com/components/vaadin-upload/html-examples/upload-limit-files-demos

But it’s not being exposed in the component, however the functionality exists in GeneratedVaadinUpload.addFileRejectListener I tried to expose it but got a ClassCastException in JsonCodec.decodeAs from flow-server https://github.com/vaadin/flow/blob/master/flow-server/src/main/java/com/vaadin/flow/internal/JsonCodec.java#L244

java.lang.ClassCastException: Cannot cast elemental.json.impl.JreJsonString to elemental.json.JsonObject

I’ll try to look into fixing it later. Any guidance is appreciated.