Skip to content

Upload componet ignores server validation of small files. #8771

@AndreRisnes

Description

@AndreRisnes

Description

We have an Upload + TransferProgressAwareHandler with a handleUploadRequest() that calls notifyError() to signal a failed upload (because of a file validation error). This works when uploading large files, but for small files, the client seemingly decides that the upload was successful before handleUploadRequest has a say in it, and displays failed files as successful in the Upload component's file list.

notifyError is called on the server, but the client still sends this:

Sending xhr message to server: {"csrfToken":"943b511e-da80-450d-9fa6-c0aba20effcc","rpc":[{"type":"event","node":561,"event":"upload-success","data":{"element.files":[{"loaded":32768,"held":false,"status":"","xhr":{},"uploadTarget":"VAADIN/dynamic/resource/0/863e8c02-6d46-45f5-af39-991b00327859/upload","indeterminate":false,"uploading":false,"error":false,"abort":false,"complete":true,"progress":100}]}}],"syncId":31,"clientId":31}

Expected outcome

I expect that errors signaled in handleUploadRequest are reflected in the file list, regardless of file size

Minimal reproducible example

class ReproUploadHandler extends TransferProgressAwareHandler<UploadEvent, ReproUploadHandler> implements UploadHandler {
    @Override
    public void handleUploadRequest(UploadEvent event) throws IOException {
        notifyError(event, new IOException("test error"));
    }

    @Override
    protected TransferContext getTransferContext(UploadEvent transferEvent) {
        return new TransferContext(transferEvent.getRequest(),
                transferEvent.getResponse(), transferEvent.getSession(),
                transferEvent.getFileName(), transferEvent.getOwningElement(),
                transferEvent.getFileSize());
    }
}

And in some view class:

var upload = new Upload(new ReproUploadHandler());
upload.setMaxFiles(1);  //Not sure if this is significant 
// add upload to the view.

Steps to reproduce

Create a view and add an Upload with the code above. Try to upload a small file (my test file is 32K).

Environment

Vaadin version(s): 25.0.5
OS: Ubuntu 20.04.6
Browser: FF 136.0 (not sure if significant)

Browsers

Firefox

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions