Class UploadButton

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.button.Button
com.vaadin.flow.component.upload.UploadButton
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<com.vaadin.flow.component.button.Button>, com.vaadin.flow.component.ClickNotifier<com.vaadin.flow.component.button.Button>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<com.vaadin.flow.component.button.Button>, com.vaadin.flow.component.FocusNotifier<com.vaadin.flow.component.button.Button>, com.vaadin.flow.component.HasAriaLabel, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasText, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.shared.HasPrefix, com.vaadin.flow.component.shared.HasSuffix, com.vaadin.flow.component.shared.HasThemeVariant<com.vaadin.flow.component.button.ButtonVariant>, com.vaadin.flow.component.shared.HasTooltip, Serializable

@Tag("vaadin-upload-button") @NpmPackage(value="@vaadin/upload", version="https://pkg.pr.new/vaadin/web-components/@vaadin/upload@3141b6e97ee28811344a2e851112c4ba1ae340ce") @JsModule("@vaadin/upload/src/vaadin-upload-button.js") public class UploadButton extends com.vaadin.flow.component.button.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:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier

    com.vaadin.flow.component.BlurNotifier.BlurEvent<C extends com.vaadin.flow.component.Component>

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.Focusable

    com.vaadin.flow.component.Focusable.FocusJs

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier

    com.vaadin.flow.component.FocusNotifier.FocusEvent<C extends com.vaadin.flow.component.Component>

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasText

    com.vaadin.flow.component.HasText.WhiteSpace
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new upload button without a manager.
    Creates a new upload button linked to the given manager.
    Creates a new upload button with the given text, linked to the given manager.
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the device input that is used for capturing a new file.
    Gets the upload manager that this component is linked to.
    void
    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.
    void
    setEnabled(boolean enabled)
    Sets whether this button is enabled.
    default void
    Sets the upload manager that this component is linked to.

    Methods inherited from class com.vaadin.flow.component.button.Button

    addBlurListener, addFocusListener, addFocusShortcut, bindEnabled, bindText, click, clickInClient, getDisableOnClickMode, getDownloadHandler, getIcon, getText, isAutofocus, isDisableOnClick, isIconAfterText, remove, setAutofocus, setDisableOnClick, setDisableOnClick, setDownloadHandler, setIcon, setIconAfterText, setText

    Methods inherited from class com.vaadin.flow.component.Component

    addListener, bindVisible, findAncestor, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTestId, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, getUIOrThrow, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setTestId, setVisible, whenAttached

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.vaadin.flow.component.AttachNotifier

    addAttachListener

    Methods inherited from interface com.vaadin.flow.component.ClickNotifier

    addClickListener, addClickShortcut, addDoubleClickListener, addSingleClickListener

    Methods inherited from interface com.vaadin.flow.component.DetachNotifier

    addDetachListener

    Methods inherited from interface com.vaadin.flow.component.Focusable

    blur, focus, focus, getTabIndex, setTabIndex

    Methods inherited from interface com.vaadin.flow.component.HasAriaLabel

    getAriaLabel, getAriaLabelledBy, setAriaLabel, setAriaLabelledBy, setAriaLabelledBy

    Methods inherited from interface com.vaadin.flow.component.HasElement

    getElement

    Methods inherited from interface com.vaadin.flow.component.HasEnabled

    isEnabled

    Methods inherited from interface com.vaadin.flow.component.shared.HasPrefix

    getPrefixComponent, setPrefixComponent

    Methods inherited from interface com.vaadin.flow.component.HasSize

    bindHeight, bindWidth, getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull

    Methods inherited from interface com.vaadin.flow.component.HasStyle

    addClassName, addClassNames, bindClassName, bindClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName

    Methods inherited from interface com.vaadin.flow.component.shared.HasSuffix

    getSuffixComponent, setSuffixComponent

    Methods inherited from interface com.vaadin.flow.component.HasText

    getWhiteSpace, setWhiteSpace

    Methods inherited from interface com.vaadin.flow.component.HasTheme

    addThemeName, addThemeNames, bindThemeName, bindThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName

    Methods inherited from interface com.vaadin.flow.component.shared.HasThemeVariant

    addThemeVariants, bindThemeVariant, bindThemeVariants, removeThemeVariants, setThemeVariant, setThemeVariants, setThemeVariants

    Methods inherited from interface com.vaadin.flow.component.shared.HasTooltip

    getTooltip, setTooltipMarkdown, setTooltipText
  • 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 com.vaadin.flow.component.HasEnabled
      Overrides:
      setEnabled in class com.vaadin.flow.component.button.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