Skip to content

FileInput

<FileInput> allows editing and uploading file attachments (pdfs, csv, images, etc.). It is powered by react-dropzone.

import { FileInput, FileField } from '@/components/admin';
<FileInput source="attachments" multiple accept={{ 'image/*': [] }}>
<FileField source="src" title="title" />
</FileInput>

<FileInput> uses its child component to give a preview of the files. <FileInput> renders its child once per file, inside a <RecordContext>, so the child can be a Field component. The default <FileField> renders the name of the file(s), with a hyperlink.

The input value must be an object or an array of objects with a title and a src property, e.g.:

{
id: 123,
attachments: [
{
title: 'Invoice-2929-01-06.pdf',
src: 'https://example.com/uploads/invoice-2929-01-06.pdf',
},
{
title: 'export.pdf',
src: 'https://example.com/uploads/export.pdf',
},
],
}

After modification by the user, the value is stored as an array of objects with 3 properties:

It is the responsibility of your dataProvider to send the file to the server (encoded in Base64, or using multipart upload) and to transform the src property. See the Data Provider documentation for an example.

Files are accepted or rejected based on the accept, multiple, minSize and maxSize props.

PropRequiredTypeDefaultDescription
sourceRequiredstring-Field name
acceptOptionalDropzoneOptions['accept']-MIME / extension accept map
childrenOptionalReactNode-Preview element (single)
classNameOptionalstring-Wrapper classes
helperTextOptionalReactNode-Help text
labelMultipleOptionalstringra.input.file.upload_severali18n key multiple placeholder
labelSingleOptionalstringra.input.file.upload_singlei18n key for single placeholder
maxSizeOptionalnumber-Max bytes
minSizeOptionalnumber-Min bytes
multipleOptionalbooleanfalseAllow multiple files
onRemoveOptional(file:any)=>void-Callback after removing a file
optionsOptionalDropzoneOptions-Extra dropzone options
placeholderOptionalReactNode-Custom placeholder content
validateFileRemovalOptional(file:any)=>boolean|Promise<boolean>-Throw/cancel to prevent removal

Set to true if the input should accept a list of files, false if it should only accept one file. Defaults to false.

If multiple is set to false and additional files are dropped, all files besides the first will be rejected. Any file which does not have a size in the [minSize, maxSize] range, will be rejected as well.

<FileInput source="attachments" multiple>
<FileField source="src" title="title" />
</FileInput>