Class UploadFileHandler

java.lang.Object
com.vaadin.flow.component.Component
org.vaadin.firitin.components.upload.UploadFileHandler
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, Serializable, FluentAttachNotifier<UploadFileHandler>, FluentComponent<UploadFileHandler>, FluentDetachNotifier<UploadFileHandler>, FluentHasEnabled<UploadFileHandler>, FluentHasSize<UploadFileHandler>, FluentHasStyle<UploadFileHandler>

@Tag("vaadin-upload") public class UploadFileHandler extends com.vaadin.flow.component.Component implements FluentComponent<UploadFileHandler>, FluentHasStyle<UploadFileHandler>, FluentHasSize<UploadFileHandler>, FluentHasEnabled<UploadFileHandler>
A vaadin-upload component that just passes the input stream (and name and mime type) of the uploaded file for the developer to handle (constructor parameter). This is essentially Upload component as it should be implemented. More context from https://vaadin.com/blog/uploads-and-downloads-inputs-and-outputs

Note, that the FileHandler you write is not executed in the UI thread. If you want to modify the UI from it, by sure to use UI.access to handle locking properly.

Author:
mstahv
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • clearFiles

      public void clearFiles()
      Clears the uploaded files shown in the component.
    • allowMultiple

      public UploadFileHandler allowMultiple()
    • withAllowMultiple

      public UploadFileHandler withAllowMultiple(boolean allowMultiple)
      Configures the component to allow multiple files to be selected at once.
      Parameters:
      allowMultiple - true to allow multiple files
      Returns:
      The component for further configuration
    • withDragAndDrop

      public UploadFileHandler withDragAndDrop(boolean enableDragAndDrop)
      Configures the component to allow drag and dropping of files on selected devices (mainly desktop browsers).
      Parameters:
      enableDragAndDrop - true to allow DnD
      Returns:
      The component for further configuration
    • withClearAutomatically

      public UploadFileHandler withClearAutomatically(boolean clear)
      Parameters:
      clear - true if the upload queue should be cleaned once all uploads are done.
      Returns:
      The component for further conf
    • onAttach

      protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
      Overrides:
      onAttach in class com.vaadin.flow.component.Component
    • onDetach

      protected void onDetach(com.vaadin.flow.component.DetachEvent detachEvent)
      Overrides:
      onDetach in class com.vaadin.flow.component.Component
    • withMaxFiles

      public UploadFileHandler withMaxFiles(int maxFiles)
      Parameters:
      maxFiles - the number of files allowed to be uploaded at once
      Returns:
      The component for further configuration
    • addUploadSucceededListener

      public com.vaadin.flow.shared.Registration addUploadSucceededListener(com.vaadin.flow.component.ComponentEventListener<UploadFileHandler.UploadSucceededEvent> listener)
    • setMaxConcurrentUploads

      public void setMaxConcurrentUploads(int maxConcurrentUploads)
      Sets the maximum number of server connections this upload uses if multiple files are chosen.
      Parameters:
      maxConcurrentUploads - the number of maximum connections for upload
    • setUploadButton

      public void setUploadButton(com.vaadin.flow.component.Component button)
      Set the component as the actionable button inside the upload component, that opens the dialog for choosing the files to be upload.
      Parameters:
      button - the component to be clicked by the user to open the dialog, or null to reset to the default button
    • withUploadButton

      public UploadFileHandler withUploadButton(com.vaadin.flow.component.Component button)
      Set the component as the actionable button inside the upload component, that opens the dialog for choosing the files to be upload.
      Parameters:
      button - the component to be clicked by the user to open the dialog, or null to reset to the default button
      Returns:
      this for further config
    • setAcceptedFileTypes

      public void setAcceptedFileTypes(String... acceptedFileTypes)
      Specify the types of files that the server accepts. Syntax: a MIME type pattern (wildcards are allowed) or file extensions. Notice that MIME types are widely supported, while file extensions are only implemented in certain browsers, so it should be avoided.

      Example: "video/*","image/tiff" or ".pdf","audio/mp3"

      Parameters:
      acceptedFileTypes - the allowed file types to be uploaded, or null to clear any restrictions
    • withAcceptedFileTypes

      public UploadFileHandler withAcceptedFileTypes(String... acceptedFileTypes)
    • setDropLabel

      public void setDropLabel(com.vaadin.flow.component.Component label)
      Set the component to show as a message to the user to drop files in the upload component. Despite of the name, the label can be any component.
      Parameters:
      label - the label to show for the users when it's possible drop files, or null to reset to the default label
    • withDropLabel

      public UploadFileHandler withDropLabel(com.vaadin.flow.component.Component label)
    • setDropLabelIcon

      public void setDropLabelIcon(com.vaadin.flow.component.Component icon)
      Set the component to show as the drop label icon. The icon is visible when the user can drop files to this upload component. Despite of the name, the drop label icon can be any component.
      Parameters:
      icon - the label icon to show for the users when it's possible to drop files, or null to reset to the default icon
    • withDropLabelIcon

      public UploadFileHandler withDropLabelIcon(com.vaadin.flow.component.Component icon)
    • setI18n

      public void setI18n(com.vaadin.flow.component.upload.UploadI18N i18n)
      Set the internationalization properties for this component.
      Parameters:
      i18n - the internationalized properties, not null
    • onEnabledStateChanged

      public void onEnabledStateChanged(boolean enabled)
      Overrides:
      onEnabledStateChanged in class com.vaadin.flow.component.Component