FileUpload is an advanced uploader with dragdrop support, multi file uploads, auto uploading, progress tracking and validations.
import { FileUpload } from 'primereact/fileupload';
FileUpload basic mode provides a simpler UI as an alternative to default advanced mode.
<Toast ref={toast}></Toast>
<FileUpload mode="basic" name="demo[]" url="/api/upload" accept="image/*" maxFileSize={1000000} onUpload={onUpload} />
When auto property is enabled, a file gets uploaded instantly after selection.
<Toast ref={toast}></Toast>
<FileUpload mode="basic" name="demo[]" url="/api/upload" accept="image/*" maxFileSize={1000000} onUpload={onUpload} auto chooseLabel="Browse" />
FileUpload is an advanced uploader with dragdrop support, multi file uploads, auto uploading, progress tracking and validations.
Drag and drop files to here to upload.
<FileUpload name="demo[]" url={'/api/upload'} multiple accept="image/*" maxFileSize={1000000} emptyTemplate={<p className="m-0">Drag and drop files to here to upload.</p>} />
Uploader UI can be customized with templating.
<Toast ref={toast}></Toast>
<Tooltip target=".custom-choose-btn" content="Choose" position="bottom" />
<Tooltip target=".custom-upload-btn" content="Upload" position="bottom" />
<Tooltip target=".custom-cancel-btn" content="Clear" position="bottom" />
<FileUpload ref={fileUploadRef} name="demo[]" url="/api/upload" multiple accept="image/*" maxFileSize={1000000}
onUpload={onTemplateUpload} onSelect={onTemplateSelect} onError={onTemplateClear} onClear={onTemplateClear}
headerTemplate={headerTemplate} itemTemplate={itemTemplate} emptyTemplate={emptyTemplate}
chooseOptions={chooseOptions} uploadOptions={uploadOptions} cancelOptions={cancelOptions} />
Uploading implementation can be overriden with customUpload property and defining a custom uploadHandler function.
<FileUpload mode="basic" name="demo[]" url="/api/upload" accept="image/*" customUpload uploadHandler={customBase64Uploader} />
Following is the list of structural style classes, for theming classes visit theming page.
Name | Element |
---|---|
p-fileupload | Container element. |
p-fileupload-buttonbar | Header containing the buttons. |
p-fileupload-content | Content section. |
FileUpload uses a hidden native input element with type="file" for screen readers.
Interactive elements of the uploader are buttons, visit the Button accessibility section for more information.