FileUpload API

API documentation for FileUpload component

FileUpload#

Props#

Defines valid properties in FileUpload component.

nametypedefaultdescription
refRef<unknown>
null
The reference to the component instance.
pIfboolean
true
Whether the component should be rendered.
styleCSSProperties | ((instance?: FileUploadInstance) => CSSProperties)
null
The style to apply to the component.
classNamestring | ((instance?: FileUploadInstance) => string)
null
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>
null
The component type to render.
asChildboolean
false
Whether the component should be rendered as a child component.
ptSafeRecord<FileUploadPassThrough>
null
The pass-through props to pass to the component
ptOptionsPassThroughOptions
null
The pass-through options to pass to the component
unstyledboolean
null
Whether the component should be rendered without classes.
dtunknown
null
The design token to use for the component.
stylesStylesOptions<ComponentInstance>
null
The styles to use for the component.
childrenReactNode | ((instance: FileUploadInstance) => ReactNode)
null
The children to render.
namestring
null
Name of the request parameter to identify the files at backend.
urlstring
null
Remote url to upload the files.
multipleboolean
false
Used to select multiple files at once from file dialog.
acceptstring
null
Pattern to restrict the allowed file types such as "image/*".
disabledboolean
false
When present, it specifies that the element should be disabled.
autoboolean
false
When enabled, upload begins automatically after selection is completed.
maxFileSizenumber
null
Maximum file size allowed in bytes.
fileLimitnumber
null
Maximum number of files that can be uploaded.
withCredentialsboolean
false
Cross-site Access-Control requests should be made using credentials such as cookies, authorization headers or TLS client certificates.
customUploadboolean
false
Whether to use the default upload or a manual implementation defined in uploadHandler callback.
invalidFileLimitMessagestring
'Maximum number of files exceeded, limit is {0} at most.'
Message to display when number of files to be uploaded exceeds the limit.
invalidFileSizeMessagestring
'{0}: Invalid file size, file size should be smaller than {1}.'
Message to display when file size exceeds the limit.
invalidFileTypeMessagestring
'{0}: Invalid file type, allowed file types: {1}.'
Message to display when file type is not allowed.
uploadHandler(event: FileUploadHandlerEvent) => void
null
Callback to invoke to implement a custom upload.
onSelect(event: FileUploadSelectEvent) => void
null
Callback to invoke when files are selected.
onBeforeUpload(event: FileUploadBeforeUploadEvent) => void
null
Callback to invoke before file upload begins to customize the request such as post parameters before the files.
onUpload(event: FileUploadUploadEvent) => void
null
Callback to invoke when file upload is complete.
onError(event: FileUploadErrorEvent) => void
null
Callback to invoke if file upload fails.
onProgress(event: FileUploadProgressEvent) => void
null
Callback to invoke on upload progress.
onBeforeSend(event: FileUploadBeforeSendEvent) => void
null
Callback to invoke before send for customization such as adding headers.
onClear() => void
null
Callback to invoke when files in queue are removed without uploading.
onRemove(event: FileUploadRemoveEvent) => void
null
Callback to invoke when a file is removed.
[key: string]any
null
pt-{optionName}-*-
null
Pass through attributes for customizing component. For more info, see Pass Through tab.

State#

Defines valid state in FileUpload component.

nametypedefaultdescription
filesFile[]
null
List of currently selected files to be uploaded.
messagesstring[]
null
Validation or error messages.
progressnumber
null
Current upload progress as a percentage (0-100).
uploadedFilesFile[]
null
List of successfully uploaded files.

Exposes#

Defines the methods and properties exposed by FileUpload component.

nametypedefaultdescription
stateuseFileUploadState
null
State of the file upload.
uploadedFileCount{ current: number }
null
Reference to track the number of uploaded files for file limit validation.
hasFilesboolean
null
Indicates whether there are files selected for upload.
hasUploadedFilesboolean
null
Indicates whether there are files that have been successfully uploaded.
inputRefRefObject<HTMLInputElement>
null
Reference to the file input element.
contentRefRefObject<HTMLDivElement>
null
Reference to the content element for drag and drop support.
upload() => void
null
Initiates the upload process for selected files.
choose() => void
null
Programmatically triggers the file selection dialog.
clear() => void
null
Clears all selected files and messages.
remove(index: number) => void
null
Removes a file from the selected files list by index.
removeUploadedFile(index: number) => void
null
Removes a file from the uploaded files list by index.
formatSize(bytes: number) => string
null
Formats a file size in bytes to a human-readable string.
onFileSelect(event: ChangeEvent<HTMLInputElement>) => void
null
Handler for file selection from input or drag-and-drop.
onDragEnter(event: DragEvent) => void
null
Handler for drag enter event.
onDragOver(event: DragEvent) => void
null
Handler for drag over event.
onDragLeave() => void
null
Handler for drag leave event.
onDrop(event: DragEvent) => void
null
Handler for drop event.

Interfaces#

Defines passthrough(pt) options of FileUpload component.

nametypedefaultdescription
rootFileUploadPassThroughType<HTMLAttributes<HTMLDivElement>>
null
Used to pass attributes to the root's DOM element.
contentFileUploadPassThroughType<HTMLAttributes<HTMLDivElement>>
null
Used to pass attributes to the content's DOM element.
fileListFileUploadPassThroughType<HTMLAttributes<HTMLDivElement>>
null
Used to pass attributes to the file list's DOM element.
fileFileUploadPassThroughType<HTMLAttributes<HTMLDivElement>>
null
Used to pass attributes to the file's DOM element.
fileThumbnailFileUploadPassThroughType<HTMLAttributes<HTMLImageElement>>
null
Used to pass attributes to the file thumbnail's DOM element.
fileInfoFileUploadPassThroughType<HTMLAttributes<HTMLDivElement>>
null
Used to pass attributes to the file info's DOM element.
fileNameFileUploadPassThroughType<HTMLAttributes<HTMLDivElement>>
null
Used to pass attributes to the fileName's DOM element.
fileSizeFileUploadPassThroughType<HTMLAttributes<HTMLDivElement>>
null
Used to pass attributes to the fileSize's DOM element.
fileActionsFileUploadPassThroughType<HTMLAttributes<HTMLDivElement>>
null
Used to pass attributes to the file actions' DOM element.

Types#

Instance of FileUpload component.

values
ComponentInstance<FileUploadProps, FileUploadState, FileUploadExposes>

FileUploadContent#

Props#

Defines valid properties in FileUploadContent component.

nametypedefaultdescription
refRef<unknown>
null
The reference to the component instance.
pIfboolean
true
Whether the component should be rendered.
styleCSSProperties | ((instance?: FileUploadContentInstance) => CSSProperties)
null
The style to apply to the component.
classNamestring | ((instance?: FileUploadContentInstance) => string)
null
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>
null
The component type to render.
asChildboolean
false
Whether the component should be rendered as a child component.
ptSafeRecord<FileUploadContentPassThrough>
null
The pass-through props to pass to the component
ptOptionsPassThroughOptions
null
The pass-through options to pass to the component
unstyledboolean
null
Whether the component should be rendered without classes.
dtunknown
null
The design token to use for the component.
stylesStylesOptions<ComponentInstance>
null
The styles to use for the component.
childrenReactNode | ((instance: FileUploadContentInstance) => ReactNode)
null
The children to render.
[key: string]any
null
pt-{optionName}-*-
null
Pass through attributes for customizing component. For more info, see Pass Through tab.

Exposes#

Defines the methods and properties exposed by FileUploadContent component.

nametypedefaultdescription
fileuploadFileUploadInstance
null
Instance of the FileUpload component.

Interfaces#

Defines passthrough(pt) options of FileUploadContent component.

nametypedefaultdescription
rootFileUploadContentPassThroughType<HTMLAttributes<HTMLButtonElement>>
null
Used to pass attributes to the root's DOM element.

Types#

Instance of FileUploadContent component.

values
ComponentInstance<FileUploadContentProps, FileUploadContentState, FileUploadContentExposes>

FileUploadList#

Props#

Defines valid properties in FileUploadList component.

nametypedefaultdescription
refRef<unknown>
null
The reference to the component instance.
pIfboolean
true
Whether the component should be rendered.
styleCSSProperties | ((instance?: FileUploadListInstance) => CSSProperties)
null
The style to apply to the component.
classNamestring | ((instance?: FileUploadListInstance) => string)
null
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>
null
The component type to render.
asChildboolean
false
Whether the component should be rendered as a child component.
ptSafeRecord<FileUploadListPassThrough>
null
The pass-through props to pass to the component
ptOptionsPassThroughOptions
null
The pass-through options to pass to the component
unstyledboolean
null
Whether the component should be rendered without classes.
dtunknown
null
The design token to use for the component.
stylesStylesOptions<ComponentInstance>
null
The styles to use for the component.
childrenReactNode | ((instance: FileUploadListInstance) => ReactNode)
null
The children to render.
[key: string]any
null
pt-{optionName}-*-
null
Pass through attributes for customizing component. For more info, see Pass Through tab.

Exposes#

Defines the methods and properties exposed by FileUploadList component.

nametypedefaultdescription
fileuploadFileUploadInstance
null
Instance of the FileUpload component.

Interfaces#

Defines passthrough(pt) options of FileUploadList component.

nametypedefaultdescription
rootFileUploadListPassThroughType<HTMLAttributes<HTMLButtonElement>>
null
Used to pass attributes to the root's DOM element.
fileListFileUploadListPassThroughType<HTMLAttributes<HTMLDivElement>>
null
Used to pass attributes to the file list's DOM element.
fileFileUploadListPassThroughType<HTMLAttributes<HTMLDivElement>>
null
Used to pass attributes to the file's DOM element.
fileThumbnailFileUploadListPassThroughType<HTMLAttributes<HTMLImageElement>>
null
Used to pass attributes to the file thumbnail's DOM element.
fileInfoFileUploadListPassThroughType<HTMLAttributes<HTMLDivElement>>
null
Used to pass attributes to the file info's DOM element.
fileNameFileUploadListPassThroughType<HTMLAttributes<HTMLDivElement>>
null
Used to pass attributes to the fileName's DOM element.
fileSizeFileUploadListPassThroughType<HTMLAttributes<HTMLDivElement>>
null
Used to pass attributes to the fileSize's DOM element.
fileActionsFileUploadListPassThroughType<HTMLAttributes<HTMLDivElement>>
null
Used to pass attributes to the file actions' DOM element.

Types#

Instance of FileUploadList component.

values
ComponentInstance<FileUploadListProps, FileUploadListState, FileUploadListExposes>

useFileUpload#

Props#

Defines valid properties in useFileUpload.

nametypedefaultdescription
namestring
null
Name of the request parameter to identify the files at backend.
urlstring
null
Remote url to upload the files.
multipleboolean
false
Used to select multiple files at once from file dialog.
acceptstring
null
Pattern to restrict the allowed file types such as "image/*".
disabledboolean
false
When present, it specifies that the element should be disabled.
autoboolean
false
When enabled, upload begins automatically after selection is completed.
maxFileSizenumber
null
Maximum file size allowed in bytes.
fileLimitnumber
null
Maximum number of files that can be uploaded.
withCredentialsboolean
false
Cross-site Access-Control requests should be made using credentials such as cookies, authorization headers or TLS client certificates.
customUploadboolean
false
Whether to use the default upload or a manual implementation defined in uploadHandler callback.
invalidFileLimitMessagestring
'Maximum number of files exceeded, limit is {0} at most.'
Message to display when number of files to be uploaded exceeds the limit.
invalidFileSizeMessagestring
'{0}: Invalid file size, file size should be smaller than {1}.'
Message to display when file size exceeds the limit.
invalidFileTypeMessagestring
'{0}: Invalid file type, allowed file types: {1}.'
Message to display when file type is not allowed.
uploadHandler(event: FileUploadHandlerEvent) => void
null
Callback to invoke to implement a custom upload.
onSelect(event: FileUploadSelectEvent) => void
null
Callback to invoke when files are selected.
onBeforeUpload(event: FileUploadBeforeUploadEvent) => void
null
Callback to invoke before file upload begins to customize the request such as post parameters before the files.
onUpload(event: FileUploadUploadEvent) => void
null
Callback to invoke when file upload is complete.
onError(event: FileUploadErrorEvent) => void
null
Callback to invoke if file upload fails.
onProgress(event: FileUploadProgressEvent) => void
null
Callback to invoke on upload progress.
onBeforeSend(event: FileUploadBeforeSendEvent) => void
null
Callback to invoke before send for customization such as adding headers.
onClear() => void
null
Callback to invoke when files in queue are removed without uploading.
onRemove(event: FileUploadRemoveEvent) => void
null
Callback to invoke when a file is removed.

State#

Defines valid state in useFileUpload.

nametypedefaultdescription
filesFile[]
null
List of currently selected files to be uploaded.
messagesstring[]
null
Validation or error messages.
progressnumber
null
Current upload progress as a percentage (0-100).
uploadedFilesFile[]
null
List of successfully uploaded files.

Exposes#

Defines the methods and properties exposed by useFileUpload.

nametypedefaultdescription
stateuseFileUploadState
null
State of the file upload.
uploadedFileCount{ current: number }
null
Reference to track the number of uploaded files for file limit validation.
hasFilesboolean
null
Indicates whether there are files selected for upload.
hasUploadedFilesboolean
null
Indicates whether there are files that have been successfully uploaded.
inputRefRefObject<HTMLInputElement>
null
Reference to the file input element.
contentRefRefObject<HTMLDivElement>
null
Reference to the content element for drag and drop support.
upload() => void
null
Initiates the upload process for selected files.
choose() => void
null
Programmatically triggers the file selection dialog.
clear() => void
null
Clears all selected files and messages.
remove(index: number) => void
null
Removes a file from the selected files list by index.
removeUploadedFile(index: number) => void
null
Removes a file from the uploaded files list by index.
formatSize(bytes: number) => string
null
Formats a file size in bytes to a human-readable string.
onFileSelect(event: ChangeEvent<HTMLInputElement>) => void
null
Handler for file selection from input or drag-and-drop.
onDragEnter(event: DragEvent) => void
null
Handler for drag enter event.
onDragOver(event: DragEvent) => void
null
Handler for drag over event.
onDragLeave() => void
null
Handler for drag leave event.
onDrop(event: DragEvent) => void
null
Handler for drop event.

Events#

Custom upload handler event

nametypedescription
filesFile[]List of files to be uploaded.
options{ clear: () => void; props: useFileUploadProps }Options object containing utility methods and component properties.

Custom file select event.

nametypedescription
originalEventChangeEvent<HTMLInputElement> | DragEventOriginal browser event.
filesFile[]List of selected files.

Custom file remove event.

nametypedescription
fileFileRemoved file.

Custom before upload event.

nametypedescription
xhrXMLHttpRequestXmlHttpRequest instance.
filesFile[]Files to be uploaded.

Custom upload event.

nametypedescription
xhrXMLHttpRequestXmlHttpRequest instance.
filesFile[]Uploaded files.

Custom error event.

nametypedescription
xhrXMLHttpRequestXmlHttpRequest instance.
filesFile[]Files that failed to upload.

Custom progress event.

nametypedescription
originalEventProgressEventOriginal browser event.
progressnumberCalculated progress value.

Custom before send event.

nametypedescription
xhrXMLHttpRequestXmlHttpRequest instance.
formDataFormDataFormData object.

Types#

Instance of useFileUpload headless.

values
HeadlessInstance<useFileUploadProps, useFileUploadState, useFileUploadExposes>