Class Upload
- All Implemented Interfaces:
AttachNotifier,DetachNotifier,HasElement,HasEnabled,HasSize,HasStyle,Serializable
- Author:
- Vaadin Ltd.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionUpload()Create a new instance of Upload.Deprecated, for removal: This API element is subject to removal in a future version.Upload(UploadHandler handler) Create a new instance of Upload with the given upload handler. -
Method Summary
Modifier and TypeMethodDescriptionAdd listener that is informed on all uploads finished.addFailedListener(ComponentEventListener<FailedEvent> listener) Deprecated, for removal: This API element is subject to removal in a future version.useTransferProgressListenerwithUploadHandlerimplementing theTransferProgressAwareHandlerinterface.Adds a listener forfile-rejectevents fired when a file cannot be added due to some constrains:setMaxFileSize, setMaxFiles, setAcceptedFileTypesAdds a listener for events fired when a file is removed.Deprecated, for removal: This API element is subject to removal in a future version.useTransferProgressListenerwithUploadHandlerimplementing theTransferProgressAwareHandlerinterface.Deprecated, for removal: This API element is subject to removal in a future version.useTransferProgressListenerwithUploadHandlerimplementing theTransferProgressAwareHandlerinterface.addStartedListener(ComponentEventListener<StartedEvent> listener) Deprecated, for removal: This API element is subject to removal in a future version.useTransferProgressListenerwithUploadHandlerimplementing theTransferProgressAwareHandlerinterface.Deprecated, for removal: This API element is subject to removal in a future version.useTransferProgressListenerwithUploadHandlerimplementing theTransferProgressAwareHandlerinterface.voidClear the list of files being processed, or already uploaded.protected voidfireUpdateProgress(long totalBytes, long contentLength) Deprecated.since 24.4.protected voidfireUpdateProgress(long totalBytes, long contentLength, String fileName) Emit the progress event.Get the list of accepted file types for upload.Get the component set as the drop label.Get the component set as the drop label icon.getI18n()Get the internationalization object previously set for this component.intGet the maximum number of files allowed for the user to select to upload.intGet the maximum allowed file size in the client-side, in bytes.Deprecated, for removal: This API element is subject to removal in a future version.Get the component set as the upload button for the upload.voidInterrupt the upload currently being received.booleanGet the auto upload status.booleanGet whether file dropping is allowed or not.booleanIs upload in progress.protected voidonAttach(AttachEvent attachEvent) Called when the component is attached to a UI.voidsetAcceptedFileTypes(String... acceptedFileTypes) Specify the types of files that the Upload web-component accepts.voidsetAutoUpload(boolean autoUpload) Whenfalse, it prevents uploads from triggering immediately upon adding file(s).voidsetDropAllowed(boolean dropAllowed) Define whether the element supports dropping files on it for uploading.voidsetDropLabel(Component label) Set the component to show as a message to the user to drop files in the upload component.voidsetDropLabelIcon(Component icon) Set the component to show as the drop label icon.voidsetI18n(UploadI18N i18n) Set the internationalization properties for this component.voidsetMaxFiles(int maxFiles) Limit of files to upload, by default it is unlimited.voidsetMaxFileSize(int maxFileSize) Specify the maximum file size in bytes allowed to upload.voidsetReceiver(Receiver receiver) Deprecated, for removal: This API element is subject to removal in a future version.usesetUploadHandler(UploadHandler)insteadvoidsetUploadButton(Component button) Set the component as the actionable button inside the upload component, that opens the dialog for choosing the files to be upload.voidsetUploadHandler(UploadHandler handler) Set the upload handler to be used for this upload component.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, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabledMethods 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, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Constructor Details
-
Upload
public Upload()Create a new instance of Upload.The upload handler must be set through
setUploadHandler(UploadHandler)before performing an upload. -
Upload
Deprecated, for removal: This API element is subject to removal in a future version.useUpload(UploadHandler)insteadCreate a new instance of Upload with the given receiver.- Parameters:
receiver- receiver that handles the upload
-
Upload
Create a new instance of Upload with the given upload handler.- Parameters:
handler- upload handler that handles the upload, notnull
-
-
Method Details
-
addAllFinishedListener
Add listener that is informed on all uploads finished.- Parameters:
listener- all finished listener to add- Returns:
- a
Registrationfor removing the event listener
-
setMaxFiles
public void setMaxFiles(int maxFiles) Limit of files to upload, by default it is unlimited. If the value is set to one, the native file browser will prevent selecting multiple files.- Parameters:
maxFiles- the maximum number of files allowed for the user to select
-
getMaxFiles
public int getMaxFiles()Get the maximum number of files allowed for the user to select to upload.- Returns:
- the maximum number of files
-
setMaxFileSize
public void setMaxFileSize(int maxFileSize) Specify the maximum file size in bytes allowed to upload. Notice that it is a client-side constraint, which will be checked before sending the request.- Parameters:
maxFileSize- the maximum file size in bytes
-
getMaxFileSize
public int getMaxFileSize()Get the maximum allowed file size in the client-side, in bytes.- Returns:
- the maximum file size in bytes
-
setAutoUpload
public void setAutoUpload(boolean autoUpload) Whenfalse, it prevents uploads from triggering immediately upon adding file(s). The default istrue.- Parameters:
autoUpload-trueto allow uploads to start immediately after selecting files,falseotherwise.
-
isAutoUpload
public boolean isAutoUpload()Get the auto upload status.- Returns:
trueif the upload of files should start immediately after they are selected,falseotherwise.
-
setDropAllowed
public void setDropAllowed(boolean dropAllowed) Define whether the element supports dropping files on it for uploading. By default it's enabled in desktop and disabled in touch devices because mobile devices do not support drag events in general. Setting ittruemeans that drop is enabled even in touch-devices, andfalsedisables drop in all devices.- Parameters:
dropAllowed-trueto allow file dropping,falseotherwise
-
isDropAllowed
public boolean isDropAllowed()Get whether file dropping is allowed or not. By default it's enabled in desktop and disabled in touch devices because mobile devices do not support drag events in general.- Returns:
trueif file dropping is allowed,falseotherwise.
-
setAcceptedFileTypes
Specify the types of files that the Upload web-component 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"File format restrictions are checked only on the client side (browser). They indicate the hints for users as to what file types to upload. Using this method won’t restrict the uploaded file’s format on the server side. If required, it’s the responsibility of the application developer to implement application-specific restrictions on the server side in one or more of the Upload component’s event listeners (e.g., in
addSucceededListener(com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.upload.SucceededEvent>)).- Parameters:
acceptedFileTypes- the allowed file types to be uploaded, ornullto clear any restrictions
-
getAcceptedFileTypes
Get the list of accepted file types for upload.- Returns:
- a list of allowed file types, never
null.
-
setUploadButton
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, ornullto reset to the default button
-
getUploadButton
Get the component set as the upload button for the upload.- Returns:
- the actionable button, never
null.
-
setDropLabel
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, ornullto reset to the default label
-
getDropLabel
Get the component set as the drop label.- Returns:
- the drop label component, never
null.
-
setDropLabelIcon
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, ornullto reset to the default icon
-
getDropLabelIcon
Get the component set as the drop label icon.- Returns:
- the drop label icon component, never
null.
-
interruptUpload
public void interruptUpload()Interrupt the upload currently being received.The interruption will be done by the receiving thread so this method will return immediately and the actual interrupt will happen a bit later.
Note! this will interrupt all ongoing uploads in multi-upload mode.
-
isUploading
public boolean isUploading()Is upload in progress.- Returns:
- true if receiving upload
-
fireUpdateProgress
Deprecated.since 24.4. UsefireUpdateProgress(long, long, String)Emit the progress event.- Parameters:
totalBytes- bytes received so farcontentLength- actual size of the file being uploaded, if known
-
fireUpdateProgress
Emit the progress event.- Parameters:
totalBytes- bytes received so farcontentLength- actual size of the file being uploaded, if knownfileName- name of the file being uploaded
-
addProgressListener
@Deprecated(since="24.8", forRemoval=true) public Registration addProgressListener(ComponentEventListener<ProgressUpdateEvent> listener) Deprecated, for removal: This API element is subject to removal in a future version.useTransferProgressListenerwithUploadHandlerimplementing theTransferProgressAwareHandlerinterface.Add a progress listener that is informed on upload progress.- Parameters:
listener- progress listener to add- Returns:
- registration for removal of listener
-
addFailedListener
@Deprecated(since="24.8", forRemoval=true) public Registration addFailedListener(ComponentEventListener<FailedEvent> listener) Deprecated, for removal: This API element is subject to removal in a future version.useTransferProgressListenerwithUploadHandlerimplementing theTransferProgressAwareHandlerinterface.Add a succeeded listener that is informed on upload failure.- Parameters:
listener- failed listener to add- Returns:
- registration for removal of listener
-
addFinishedListener
@Deprecated(since="24.8", forRemoval=true) public Registration addFinishedListener(ComponentEventListener<FinishedEvent> listener) Deprecated, for removal: This API element is subject to removal in a future version.useTransferProgressListenerwithUploadHandlerimplementing theTransferProgressAwareHandlerinterface.Add a succeeded listener that is informed on upload finished.- Parameters:
listener- finished listener to add- Returns:
- registration for removal of listener
-
addStartedListener
@Deprecated(since="24.8", forRemoval=true) public Registration addStartedListener(ComponentEventListener<StartedEvent> listener) Deprecated, for removal: This API element is subject to removal in a future version.useTransferProgressListenerwithUploadHandlerimplementing theTransferProgressAwareHandlerinterface.Add a succeeded listener that is informed on upload start.- Parameters:
listener- start listener to add- Returns:
- registration for removal of listener
-
addSucceededListener
@Deprecated(since="24.8", forRemoval=true) public Registration addSucceededListener(ComponentEventListener<SucceededEvent> listener) Deprecated, for removal: This API element is subject to removal in a future version.useTransferProgressListenerwithUploadHandlerimplementing theTransferProgressAwareHandlerinterface.Add a succeeded listener that is informed on upload succeeded.- Parameters:
listener- succeeded listener to add- Returns:
- registration for removal of listener
-
addFileRejectedListener
Adds a listener forfile-rejectevents fired when a file cannot be added due to some constrains:setMaxFileSize, setMaxFiles, setAcceptedFileTypes- Parameters:
listener- the listener- Returns:
- a
Registrationfor removing the event listener
-
addFileRemovedListener
Adds a listener for events fired when a file is removed.- Parameters:
listener- the listener- Returns:
- a
Registrationfor removing the event listener
-
getReceiver
Deprecated, for removal: This API element is subject to removal in a future version.Return the current receiver.Will return null when used with the UploadHandler which is recommended.
- Returns:
- the StreamVariable.
-
setReceiver
Deprecated, for removal: This API element is subject to removal in a future version.usesetUploadHandler(UploadHandler)insteadSet the receiver implementation that should be used for this upload component.Note! If the receiver doesn't implement
MultiFileReceiverthen the upload will be automatically set to only accept one file.- Parameters:
receiver- receiver to use for file reception- See Also:
-
setUploadHandler
Set the upload handler to be used for this upload component.The given handler defines how uploaded file content is handled on the server and invoked per each single file to be uploaded. Note! This method overrides the receiver set by
setReceiver(Receiver).- Parameters:
handler- upload handler to use for file receptions, notnull
-
setI18n
Set the internationalization properties for this component.- Parameters:
i18n- the i18n object, notnull
-
onAttach
Description copied from class:ComponentCalled when the component is attached to a UI.This method is invoked before the
Make sure to callAttachEventis fired for the component.super.onAttachwhen overriding this method. -
getI18n
Get the internationalization object previously set for this component.NOTE: Updating the instance that is returned from this method will not update the component if not set again using
setI18n(UploadI18N)- Returns:
- the i18n object or
nullif no i18n object has been set
-
clearFileList
public void clearFileList()Clear the list of files being processed, or already uploaded.
-
Upload(UploadHandler)instead