File Uploader
File uploader allow users to select one or multiple files to upload to a specific location.
Example
Variants
Custom Text
You can specify the text content of a component by providing textContent
and browseButtonLabel
props.
Custom dataTestId
You can now test the component using custom testid using dataTestId
component.
Disabled
File Types
You can add a list of allowed file types to let users upload only files of these types.
If the type of the selected file doesn't list in the allowedTypes
array then the user could be notified about the error with typeErrorText
. And allowedTypes
provides hints for browsers to guide users towards selecting the correct file types.
Handle Failed Requests
You can use onRequestError
prop to get the error response data after a failed upload or delete request.
HasNoDeleteEndpoint
If you are doing something else other than saving the uploaded file on the server, you may not have a deleteEndpoint
.
You can use the hasNoDeleteEndpoint
prop to allow deleting the file after a successful response
Label and Info Text
Use an info text to give specific instructions to help users correctly fill in the data.
You can also use it to clarify how the data will be used.
onUploadSuccess
You can use the onUploadSuccess
prop to get the response data after upload success.
onUploading
You can use onUploading
prop as a callback to get the file which is uploading in case of you don't need upload immediately. And this prop is required if postEndpoint
is not provided.
Optional field
You can show the field as optional or custom text by using the optionalText
prop as string.
Programmatically Reset
You can programmatically reset or remove uploaded files using resetUploads
function from FileUploaderContext
.
N.B. The FileUploader
should be wrapped in a FileUploaderProvider
Props
Name | Type | Default |
---|---|---|
deleteEndpoint Endpoint of the DELETE request |
| — |
hasNoDeleteEndpoint You can use this prop to allow delete without specifying a deleteEndpoint. |
| — |
postEndpoint Endpoint of the POST request |
| — |
fieldName You can specify the field name in the internal form.
It will be used by your Backend to process POST requests. |
| "file" |
withCredentials Indicates whether or not cross-site Access-Control requests should be made using credentials |
| false |
postHeaders Custom headers to be sent with a POST request |
| — |
deleteHeaders Custom headers to be sent with a DELETE request |
| — |
allowedTypes List of allowed file types |
| — |
size Size of the file uploader |
| "medium" |
multiple Use this prop to allow multiple selection |
| true |
disabled Use this prop if the component should not be interactive |
| false |
label The label of the file uploader |
| — |
infoText Use this prop to help end-users interact with the component |
| — |
typeErrorMessage This message will be displayed if one of the selected files
has a type not included in the allowedTypes list. |
| — |
selectErrorMessage This message will be displayed if the selection was unsuccessful.
(e.g. multiple files are selected but the multiple prop is set to "false") |
| — |
uploadErrorMessage This message will be displayed if the uploading failed |
| — |
deleteErrorMessage This message will be displayed if the deletion failed |
| — |
textContent This text will be displayed right before the browse button |
| "Drag & drop your files or" |
browseButtonLabel The label of the browse button |
| "Browse" |
id Native HTML attribute: Link .
Internally, this component uses a random id. We use it to associate an input with a label element.
As the random id might break snapshot tests it can be overridden by setting an explicit id. |
| — |
required Native HTML attribute: Link |
| — |
optionalText |
| — |
onUploadSuccess You can use this prop to get response data on upload success |
| — |
onDeleteSuccess You can use this prop to get response on delete |
| — |
onRequestError You can use this prop to get error response data when upload or delete fails |
| — |
onUploading This prop is required if postEndpoint is not provided. You can use this callback to get the file is uploading. |
| — |
dataTestId Data-testid for the component |
| — |
css Add custom styles to this component. Use with caution. Learn more here: Link |
| — |
inputFieldCss |
| — |
data-{foo} Data attributes can be used by testing libraries to retrieve components or assert their existence |
| — |
* - the prop is required. |