Skip to content

File Upload

Used to select files to be uploaded from the user’s device.

import { useState } from 'react';
// Import component
import { FileUpload } from '@fintech-sandpit/ui/react';
// Import styles (optional). Please note that you need to import the styles
// for Button, Icon and FileUpload components since the FileUpload component
// is composed of these components.
import '@fintech-sandpit/ui/style/components/button.css';
import '@fintech-sandpit/ui/style/components/icon.css';
import '@fintech-sandpit/ui/style/components/file_upload.css';
const [files, setFiles] = useState<File[]>([]);
return (
<FileUpload
value={files}
accept=".jpg,.png"
maxFileSize={256 * 1024}
dropZoneLabel={(
<div className="text-center text-sm">
<p>
Click to upload, or drag and drop your file here.
</p>
<p className="space-x-2">
<span>
Accepted:
</span>
<strong>
JPG, PNG &ndash; Max 256 KB
</strong>
</p>
</div>
) : undefined}
onChange={setFiles}
onReject={(file, errors) => {
alert(errors[0]);
}}
/>
);
NameTypeDefaultDescription
valueFile[]—The list of files to be uploaded
labelstring—The label of the file upload
namestring—The name of the file upload
acceptstring | string[]—The accepted file types
dropZoneboolean—Whether to use a drop zone
dropZoneInnerReactNode—The content of the drop zone
dropZoneLabelReactNode—The content of the drop zone label
multipleboolean—Whether to allow multiple files
maxFilesnumber—The maximum number of files to upload
minFileSizenumber—The minimum file size
maxFileSizenumber—The maximum file size
uploadTriggerReactNode—The content of the upload trigger
directoryboolean—Whether to allow directory uploads
disabledboolean—Whether the file upload is disabled
NameDescription
drop-zone-innerThe content of the drop zone
drop-zone-labelThe content of the drop zone label
upload-triggerThe content of the upload trigger
NameTypeDescription
onChange(files: File[]) => voidCallback fired when the files are added or removed
onAccept(file: File) => voidCallback fired when the file is accepted
onReject(file: File, errors: FileError[]) => voidCallback fired when the file is rejected