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>
@Uses(com.vaadin.flow.component.upload.Upload.class)
@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:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
An interface accepting file uploads.static final record
A collection of metadata about the uploaded files.static interface
static class
Event fired after succesful uploads. -
Field Summary
-
Constructor Summary
ConstructorDescriptionUploadFileHandler
(UploadFileHandler.CallbackFileHandler fileHandler) Creates a FileUploadHandler with provided CallbackFileHandler.UploadFileHandler
(UploadFileHandler.FileHandler fileHandler) Creates a basic FileUploadHandler with provided FileHandler -
Method Summary
Modifier and TypeMethodDescriptioncom.vaadin.flow.shared.Registration
addUploadSucceededListener
(com.vaadin.flow.component.ComponentEventListener<UploadFileHandler.UploadSucceededEvent> listener) void
Clears the uploaded files shown in the component.protected void
onAttach
(com.vaadin.flow.component.AttachEvent attachEvent) protected void
onDetach
(com.vaadin.flow.component.DetachEvent detachEvent) void
onEnabledStateChanged
(boolean enabled) void
setAcceptedFileTypes
(String... acceptedFileTypes) Specify the types of files that the server accepts.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.void
setDropLabelIcon
(com.vaadin.flow.component.Component icon) Set the component to show as the drop label icon.void
setI18n
(com.vaadin.flow.component.upload.UploadI18N i18n) Set the internationalization properties for this component.void
setMaxConcurrentUploads
(int maxConcurrentUploads) Sets the maximum number of server connections this upload uses if multiple files are chosen.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.withAcceptedFileTypes
(String... acceptedFileTypes) withAllowMultiple
(boolean allowMultiple) Configures the component to allow multiple files to be selected at once.withClearAutomatically
(boolean clear) withDragAndDrop
(boolean enableDragAndDrop) Configures the component to allow drag and dropping of files on selected devices (mainly desktop browsers).withDropLabel
(com.vaadin.flow.component.Component label) withDropLabelIcon
(com.vaadin.flow.component.Component icon) withMaxFiles
(int maxFiles) 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.Methods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisible
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.DetachNotifier
addDetachListener
Methods inherited from interface org.vaadin.firitin.fluency.ui.FluentAttachNotifier
withAttachListener
Methods inherited from interface org.vaadin.firitin.fluency.ui.FluentComponent
setId, setVisible, withId, withVisible
Methods inherited from interface org.vaadin.firitin.fluency.ui.FluentDetachNotifier
withDetachListener
Methods inherited from interface org.vaadin.firitin.fluency.ui.FluentHasEnabled
withEnabled
Methods inherited from interface org.vaadin.firitin.fluency.ui.FluentHasSize
withFullHeight, withFullWidth, withHeight, withMaxHeight, withMaxSize, withMaxWidth, withMinHeight, withMinSize, withMinWidth, withSize, withSizeFull, withSizeUndefined, withWidth
Methods inherited from interface org.vaadin.firitin.fluency.ui.FluentHasStyle
withAddedClassName, withClassName, withStyle
Methods inherited from interface com.vaadin.flow.component.HasElement
getElement
Methods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabled
Methods inherited from interface com.vaadin.flow.component.HasSize
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, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Field Details
-
fileHandler
-
-
Constructor Details
-
UploadFileHandler
Creates a basic FileUploadHandler with provided FileHandler- Parameters:
fileHandler
- the handler that does something with the uploaded file
-
UploadFileHandler
Creates a FileUploadHandler with provided CallbackFileHandler. The Command returned by the handler is executed in UI after the file has been handled.- Parameters:
fileHandler
- the handler that does something with the uploaded file
-
-
Method Details
-
clearFiles
public void clearFiles()Clears the uploaded files shown in the component. -
allowMultiple
-
withAllowMultiple
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
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
- 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 classcom.vaadin.flow.component.Component
-
onDetach
protected void onDetach(com.vaadin.flow.component.DetachEvent detachEvent) - Overrides:
onDetach
in classcom.vaadin.flow.component.Component
-
withMaxFiles
- 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, ornull
to reset to the default button
-
withUploadButton
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, ornull
to reset to the default button- Returns:
- this for further config
-
setAcceptedFileTypes
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, ornull
to clear any restrictions
-
withAcceptedFileTypes
-
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, ornull
to reset to the default label
-
withDropLabel
-
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, ornull
to reset to the default icon
-
withDropLabelIcon
-
setI18n
public void setI18n(com.vaadin.flow.component.upload.UploadI18N i18n) Set the internationalization properties for this component.- Parameters:
i18n
- the internationalized properties, notnull
-
onEnabledStateChanged
public void onEnabledStateChanged(boolean enabled) - Overrides:
onEnabledStateChanged
in classcom.vaadin.flow.component.Component
-