Upload. addFailedListener 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);


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>

Hello friends.

Help needed here please.

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.

This is now fixed and works properly