Class UploadButton

All Implemented Interfaces:
AttachNotifier, BlurNotifier<Button>, ClickNotifier<Button>, DetachNotifier, Focusable<Button>, FocusNotifier<Button>, HasAriaLabel, HasElement, HasEnabled, HasSize, HasStyle, HasText, HasTheme, HasPrefix, HasSuffix, HasThemeVariant<ButtonVariant>, HasTooltip, Serializable

@Tag("vaadin-upload-button") @NpmPackage(value="@vaadin/upload", version="25.4.0-alpha3") @JsModule("@vaadin/upload/src/vaadin-upload-button.js") public class UploadButton extends Button
A button component for triggering file uploads. When clicked, it opens a file picker dialog. This component is designed to work with UploadManager.

Example usage:

 var manager = new UploadManager(uploadHandler);
 var button = new UploadButton("Select Files", manager);
 add(button);
 
Since:
25.1
Author:
Vaadin Ltd.
See Also:
  • Field Details

  • Constructor Details

    • UploadButton

      public UploadButton()
      Creates a new upload button without a manager. The manager must be set later using setUploadManager(UploadManager).
    • UploadButton

      public UploadButton(UploadManager manager)
      Creates a new upload button linked to the given manager.
      Parameters:
      manager - the upload manager to link to, not null
      Throws:
      NullPointerException - if manager is null
    • UploadButton

      public UploadButton(String text, UploadManager manager)
      Creates a new upload button with the given text, linked to the given manager.
      Parameters:
      text - the button text
      manager - the upload manager to link to, not null
      Throws:
      NullPointerException - if manager is null
  • Method Details

    • getCapture

      public UploadCapture getCapture()
      Gets the device input that is used for capturing a new file.
      Returns:
      the device input used for capturing a new file, or null if not set
      Since:
      25.4
      See Also:
    • setCapture

      public void setCapture(UploadCapture capture)
      Sets the device input to use for capturing a new file, for example UploadCapture.ENVIRONMENT to take a photo with the back camera of a phone. On devices that support it, clicking the button then opens the camera or microphone directly instead of the file browser. The type of input is determined by the accepted MIME types of the manager, for example "image/*" for the camera, see UploadManager.setAcceptedMimeTypes(String...).

      This is only a hint to the browser. Devices without such an input, for example desktop browsers, ignore it and open the file browser. It does not restrict which files can be uploaded.

      The default is null, which opens the file browser.

      Parameters:
      capture - the device input to use for capturing a new file, or null to choose existing files
      Since:
      25.4
    • setEnabled

      public void setEnabled(boolean enabled)
      Sets whether this button is enabled. When disabled, the button cannot be used to select files.

      Note: Disabling this button only affects the UI and does not prevent a malicious client from initiating uploads. To securely prevent uploads, use UploadManager.setEnabled(boolean).

      Specified by:
      setEnabled in interface HasEnabled
      Overrides:
      setEnabled in class Button
      Parameters:
      enabled - true to enable the button, false to disable
      See Also:
    • getUploadManager

      default UploadManager getUploadManager()
      Gets the upload manager that this component is linked to.
      Returns:
      the upload manager, or null if not linked
    • setUploadManager

      default void setUploadManager(UploadManager manager)
      Sets the upload manager that this component is linked to.
      Parameters:
      manager - the upload manager, or null to unlink