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

Upload: Switching to Single file receiver and then back to MultiFileReceiver prevents adding multiple files #6227

Closed
HerbertsVaadin opened this issue Apr 22, 2024 · 0 comments · Fixed by #6253
Assignees
Labels

Comments

@HerbertsVaadin
Copy link

HerbertsVaadin commented Apr 22, 2024

Description

If I set receiver to instance of MemoryBuffer and then switch it to instance of MultiFileReceiver (for example MultiFileMemoryBuffer), the upload component still only allows to upload a single file.
bug-switching-upload-receiver

Workaround:
Manually set the max allowed files
upload.setMaxFiles(12);

Expected outcome

When switching to a MultiFileReceiver it should allow to upload multiple files.

Minimal reproducible example

package com.example.application.views.random;

import com.example.application.views.MainLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.radiobutton.RadioButtonGroup;
import com.vaadin.flow.component.upload.Upload;
import com.vaadin.flow.component.upload.receivers.MemoryBuffer;
import com.vaadin.flow.component.upload.receivers.MultiFileMemoryBuffer;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import jakarta.annotation.security.PermitAll;

import static com.example.application.views.random.UploadComponentView.Type.MULTI;
import static com.example.application.views.random.UploadComponentView.Type.SINGLE;

@PageTitle("Upload")
@Route(value = "upload", layout = MainLayout.class)
@PermitAll
public class UploadComponentView extends VerticalLayout {

    public UploadComponentView() {
        var upload = new Upload();

        var radioButtons = new RadioButtonGroup<Type>();
        radioButtons.setItems(Type.values());
        radioButtons.setItemLabelGenerator(Type::name);
        radioButtons.addValueChangeListener(valueChange -> {
            if (valueChange.getValue() == SINGLE) {
                upload.setReceiver(new MemoryBuffer());
            } else {
                upload.setReceiver(new MultiFileMemoryBuffer());
            }
        });
        radioButtons.setValue(MULTI);

        add(radioButtons, upload);
    }

    enum Type {
        SINGLE, MULTI
    }
}

Steps to reproduce

  1. Use the example above.
  2. Switch to SINGLE radio button
  3. Switch back to MULTI radio button
  4. Notice that Upload component only allows to upload a single file

Environment

Vaadin version(s): 24.3.9
OS: Windows 11

Browsers

Chrome, Firefox

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

Successfully merging a pull request may close this issue.

3 participants