public class Upload extends GeneratedVaadinUpload<Upload> implements HasSize
vaadin-upload
element.GeneratedVaadinUpload.FileRejectEvent<R extends GeneratedVaadinUpload<R>>, GeneratedVaadinUpload.FilesChangeEvent<R extends GeneratedVaadinUpload<R>>, GeneratedVaadinUpload.MaxFilesReachedChangeEvent<R extends GeneratedVaadinUpload<R>>, GeneratedVaadinUpload.UploadAbortEvent<R extends GeneratedVaadinUpload<R>>, GeneratedVaadinUpload.UploadBeforeEvent<R extends GeneratedVaadinUpload<R>>, GeneratedVaadinUpload.UploadErrorEvent<R extends GeneratedVaadinUpload<R>>, GeneratedVaadinUpload.UploadProgressEvent<R extends GeneratedVaadinUpload<R>>, GeneratedVaadinUpload.UploadRequestEvent<R extends GeneratedVaadinUpload<R>>, GeneratedVaadinUpload.UploadResponseEvent<R extends GeneratedVaadinUpload<R>>, GeneratedVaadinUpload.UploadRetryEvent<R extends GeneratedVaadinUpload<R>>, GeneratedVaadinUpload.UploadStartEvent<R extends GeneratedVaadinUpload<R>>, GeneratedVaadinUpload.UploadSuccessEvent<R extends GeneratedVaadinUpload<R>>
Constructor and Description |
---|
Upload()
Create a new instance of Upload.
|
Upload(Receiver receiver)
Create a new instance of Upload with the given receiver.
|
Modifier and Type | Method and Description |
---|---|
Registration |
addAllFinishedListener(ComponentEventListener<AllFinishedEvent> listener)
Add listener that is informed on all uploads finished.
|
Registration |
addFailedListener(ComponentEventListener<FailedEvent> listener)
Add a succeeded listener that is informed on upload failure.
|
Registration |
addFileRejectedListener(ComponentEventListener<FileRejectedEvent> listener)
Adds a listener for
file-reject events fired when a file cannot
be added due to some constrains:
setMaxFileSize, setMaxFiles, setAcceptedFileTypes |
Registration |
addFinishedListener(ComponentEventListener<FinishedEvent> listener)
Add a succeeded listener that is informed on upload finished.
|
Registration |
addProgressListener(ComponentEventListener<ProgressUpdateEvent> listener)
Add a progress listener that is informed on upload progress.
|
Registration |
addStartedListener(ComponentEventListener<StartedEvent> listener)
Add a succeeded listener that is informed on upload start.
|
Registration |
addSucceededListener(ComponentEventListener<SucceededEvent> listener)
Add a succeeded listener that is informed on upload succeeded.
|
protected void |
fireUpdateProgress(long totalBytes,
long contentLength)
Emit the progress event.
|
List<String> |
getAcceptedFileTypes()
Get the list of accepted file types for upload.
|
Component |
getDropLabel()
Get the component set as the drop label, if any.
|
Component |
getDropLabelIcon()
Get the component set as the drop label icon, if any.
|
UploadI18N |
getI18n()
Get the internationalization object previously set for this component.
|
int |
getMaxFiles()
Get the maximum number of files allowed for the user to select to upload.
|
int |
getMaxFileSize()
Get the maximum allowed file size in the client-side, in bytes.
|
Receiver |
getReceiver()
Return the current receiver.
|
Component |
getUploadButton()
Get the component set as the upload button for the upload, if any.
|
void |
interruptUpload()
Interrupt the upload currently being received.
|
boolean |
isAutoUpload()
Get the auto upload status.
|
boolean |
isDropAllowed()
Get whether file dropping is allowed or not.
|
boolean |
isUploading()
Is upload in progress.
|
protected void |
onAttach(AttachEvent attachEvent)
Called when the component is attached to a UI.
|
void |
setAcceptedFileTypes(String... acceptedFileTypes)
Specify the types of files that the server accepts.
|
void |
setAutoUpload(boolean autoUpload)
When
false , it prevents uploads from triggering immediately
upon adding file(s). |
void |
setDropAllowed(boolean dropAllowed)
Define whether the element supports dropping files on it for uploading.
|
void |
setDropLabel(Component dropLabel)
Set the component to show as a message to the user to drop files in the
upload component.
|
void |
setDropLabelIcon(Component dropLabelIcon)
Set the component to show as the drop label icon.
|
void |
setI18n(UploadI18N i18n)
Set the internationalization properties for this component.
|
void |
setMaxFiles(int maxFiles)
Limit of files to upload, by default it is unlimited.
|
void |
setMaxFileSize(int maxFileSize)
Specify the maximum file size in bytes allowed to upload.
|
void |
setReceiver(Receiver receiver)
Set the receiver implementation that should be used for this upload
component.
|
void |
setUploadButton(Component uploadButton)
Set the component as the actionable button inside the upload component,
that opens the dialog for choosing the files to be upload.
|
addFileRejectListener, addFilesChangeListener, addMaxFilesReachedChangeListener, addToAddButton, addToDropLabel, addToDropLabelIcon, addToFileList, addUploadAbortListener, addUploadBeforeListener, addUploadErrorListener, addUploadProgressListener, addUploadRequestListener, addUploadResponseListener, addUploadRetryListener, addUploadStartListener, addUploadSuccessListener, getAcceptString, getCaptureString, getFilesJsonArray, getFormDataNameString, getHeadersJsonObject, getI18nJsonObject, getMaxFilesDouble, getMaxFileSizeDouble, getMethodString, getTargetString, getTimeoutDouble, isMaxFilesReachedBoolean, isNoAutoBoolean, isNodropBoolean, isWithCredentialsBoolean, remove, removeAll, setAccept, setCapture, setFiles, setFormDataName, setHeaders, setI18n, setMaxFiles, setMaxFileSize, setMethod, setNoAuto, setNodrop, setTarget, setTimeout, setWithCredentials, uploadFiles
addListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, set, setElement, setId, setVisible
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getCssSize, getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull
getElement
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
addAttachListener
addDetachListener
public Upload()
The receiver must be set before performing an upload.
public Upload(Receiver receiver)
receiver
- receiver that handles the uploadpublic Registration addAllFinishedListener(ComponentEventListener<AllFinishedEvent> listener)
listener
- all finished listener to addRegistration
for removing the event listenerpublic void setMaxFiles(int maxFiles)
maxFiles
- the maximum number of files allowed for the user to selectpublic int getMaxFiles()
public void setMaxFileSize(int maxFileSize)
maxFileSize
- the maximum file size in bytespublic int getMaxFileSize()
public void setAutoUpload(boolean autoUpload)
false
, it prevents uploads from triggering immediately
upon adding file(s). The default is true
.autoUpload
- true
to allow uploads to start immediately after
selecting files, false
otherwise.public boolean isAutoUpload()
true
if the upload of files should start immediately
after they are selected, false
otherwise.public void setDropAllowed(boolean dropAllowed)
true
means that drop is enabled even in touch-devices, and
false
disables drop in all devices.dropAllowed
- true
to allow file dropping, false
otherwisepublic boolean isDropAllowed()
true
if file dropping is allowed, false
otherwise.public void setAcceptedFileTypes(String... acceptedFileTypes)
Example: "video/*","image/tiff"
or
".pdf","audio/mp3"
acceptedFileTypes
- the allowed file types to be uploaded, or null
to
clear any restrictionspublic List<String> getAcceptedFileTypes()
null
.public void setUploadButton(Component uploadButton)
uploadButton
- the component to be clicked by the user to open the dialog, or
null
to reset to the default buttonpublic Component getUploadButton()
null
if none was setpublic void setDropLabel(Component dropLabel)
dropLabel
- the label to show for the users when it's possible drop files,
or null
to clear itpublic Component getDropLabel()
null
if none was setpublic void setDropLabelIcon(Component dropLabelIcon)
dropLabelIcon
- the label icon to show for the users when it's possible to
drop files, or null
to cleat itpublic Component getDropLabelIcon()
null
if none was
setpublic void interruptUpload()
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 uploads in multi-upload mode.
public boolean isUploading()
protected void fireUpdateProgress(long totalBytes, long contentLength)
totalBytes
- bytes received so farcontentLength
- actual size of the file being uploaded, if knownpublic Registration addProgressListener(ComponentEventListener<ProgressUpdateEvent> listener)
listener
- progress listener to addpublic Registration addFailedListener(ComponentEventListener<FailedEvent> listener)
listener
- failed listener to addpublic Registration addFinishedListener(ComponentEventListener<FinishedEvent> listener)
listener
- finished listener to addpublic Registration addStartedListener(ComponentEventListener<StartedEvent> listener)
listener
- start listener to addpublic Registration addSucceededListener(ComponentEventListener<SucceededEvent> listener)
listener
- succeeded listener to addpublic Registration addFileRejectedListener(ComponentEventListener<FileRejectedEvent> listener)
file-reject
events fired when a file cannot
be added due to some constrains:
setMaxFileSize, setMaxFiles, setAcceptedFileTypes
listener
- the listenerRegistration
for removing the event listenerpublic Receiver getReceiver()
public void setReceiver(Receiver receiver)
Note! If the receiver doesn't implement MultiFileReceiver
then
the upload will be automatically set to only accept one file.
receiver
- receiver to use for file receptionpublic void setI18n(UploadI18N i18n)
i18n
- the internationalized properties, not null
protected void onAttach(AttachEvent attachEvent)
Component
The default implementation does nothing.
This method is invoked before the AttachEvent
is fired for the
component.
public UploadI18N getI18n()
Note: updating the object content that is gotten from this method will
not update the language on the component if not set back using
setI18n(UploadI18N)
null
.Copyright © 2023. All rights reserved.