Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add methods to get file queue information from Upload component #6858

Open
crowstudios opened this issue Nov 22, 2024 · 0 comments
Open

Add methods to get file queue information from Upload component #6858

crowstudios opened this issue Nov 22, 2024 · 0 comments

Comments

@crowstudios
Copy link

Describe your motivation

We need a straightforward way to find out if there are files queued for transfer in the Vaadin Upload component.

Describe the solution you'd like

For applications that do not use Auto-Upload, there is no easy way to tell if a user has added files to the queue but not yet initiated the transfer. A possible solution would be to add the following method the Java API:

Upload.getQueuedUploads()

Describe alternatives you've considered

As a workaround, we currently use JavaScript to check the length of the queue, but this requires an asynchronous callback, which is not ideal:

public void getQueueTotals(BiConsumer<Integer, Integer> callback) {
    getElement().executeJs(
        "return [ this.files.length, this.files.filter(file => file.status === 'Queued').length ];").then(
        result -> {
            JsonArray resultArray = (JsonArray) result;
            callback.accept((int) resultArray.getNumber(0), (int) resultArray.getNumber(1));
        },
        error -> log(Level.WARN, "Error occurred while trying to retrieve total files count: " + error));
}

Additional context

Adding this functionality will make it much easier to warn users if they queue files for upload but forget to initiate the transfer before navigating away from the page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant