lara-light-indigo

FileUpload

FileUpload is an advanced uploader with dragdrop support, multi file uploads, auto uploading, progress tracking and validations.

Advanced
Choose

Drag and drop files to here to upload.

Template
 
Drag and Drop Image Here
Basic
Choose
Basic with Auto
Browse
Custom (base64 encoded)
Choose
Import via Module

import { FileUpload } from 'primereact/fileupload';
 
Import via CDN

<script src="https://unpkg.com/primereact/core/core.min.js"></script>
<script src="https://unpkg.com/primereact/fileupload/fileupload.min.js"></script>
 
Getting Started

FileUpload requires a url property as the upload target and a name to identify the files at backend.


<FileUpload name="demo" url="./upload"></FileUpload>
 
Multiple Uploads

Only one file can be selected at a time by default, to allow selecting multiple files at once enable multiple option.


<FileUpload name="demo[]" url="./upload" multiple />
 
DragDrop

File selection can also be done by dragging and dropping from the filesystem to the content section of the component.

Auto Uploads

When auto property is enabled, upload begins as soon as file selection is completed or a file is dropped on the drop area.


<FileUpload name="demo" url="./upload" auto />
 
File Types

Selectable file types can be restricted with accept property, example below only allows images to be uploaded. Read more about other possible values here.


<FileUpload name="demo[]" url="./upload" multiple accept="image/*" />
 
File Size

Maximium file size can be restricted using maxFileSize property defined in bytes.


<FileUpload name="demo" url="./upload" maxFileSize="1000000" />
 

In order to customize the default messages use invalidFileSizeMessageSummary and invalidFileSizeMessageDetail options. In summary messages, 0 placeholder refers to the filename and in detail message, the file size.

  • invalidFileSizeMessageSummary: '0: Invalid file size, '
  • invalidFileSizeMessageDetail: string = 'maximum upload size is 0.'
Request Customization

XHR request to upload the files can be customized using the onBeforeUpload callback that passes the xhr instance and FormData object as event parameters.

Basic UI

FileUpload basic mode provides a simpler UI as an alternative to advanced mode.


<FileUpload name="demo" url="./upload" mode="basic" />
 
Custom Upload

Uploading implementation can be overriden by enabling customUpload property and defining a custom upload handler event.


<FileUpload name="demo[]" url="./upload" customUpload uploadHandler={myUploader} />
 

const myUploader = (event) => {
    //event.files == files to upload
}
 
ItemTemplate

Used to create custom item elements in the container.


<FileUpload name="demo[]" url="./upload" itemTemplate={customItemTemplate} uploadHandler={myUploader} />
 

const customItemTemplate = (file, props) => {
    // file: Current file object.
    // options.onRemove: Event used to remove current file in the container.
    // options.previewElement: The default preview element in the container.
    // options.fileNameElement: The default fileName element in the container.
    // options.sizeElement: The default size element in the container.
    // options.removeElement: The default remove element in the container.
    // options.formatSize: The formated size of file.
    // options.files: Current files.
    // options.index: The index of file in current files list.
    // options.element: Default element created by the component.
    // options.props: component props.
}
 
Button Options

Used to customize choose, upload and cancel buttons.


const chooseOptions = {label: 'Choose', icon: 'pi pi-fw pi-plus'};
const uploadOptions = {label: 'Uplaod', icon: 'pi pi-upload', className: 'p-button-success'};
const cancelOptions = {label: 'Cancel', icon: 'pi pi-times', className: 'p-button-danger'};
 

<FileUpload name="demo[]" url="./upload" chooseOptions={chooseOptions} uploadOptions={uploadOptions} cancelOptions={cancelOptions} uploadHandler={myUploader} />
 

const buttonOptions = {
    // label: The label of button.
    // icon: The icon of button.
    // className: Style class of button.
    // style: Style of button.
}
 
Properties
NameTypeDefaultDescription
idstringnullUnique identifier of the element.
namestringnullName of the request parameter to identify the files at backend.
urlstringnullRemote url to upload the files.
modestringadvancedDefines the UI of the component, possible values are "advanced" and "basic".
multiplebooleanfalseUsed to select multiple files at once from file dialog.
acceptstringfalsePattern to restrict the allowed file types such as "image/*".
disabledbooleanfalseDisables the upload functionality.
autobooleanfalseWhen enabled, upload begins automatically after selection is completed.
maxFileSizenumbernullMaximum file size allowed in bytes.
invalidFileSizeMessageSummarystring"{0}: Invalid file size, "Summary message of the invalid fize size.
invalidFileSizeMessageDetailstring"maximum upload size is {0}."Detail message of the invalid fize size.
styleobjectnullInline style of the component.
classNamestringnullStyle class of the component.
withCredentialsbooleanfalseCross-site Access-Control requests should be made using credentials such as cookies, authorization headers or TLS client certificates.
previewWidthnumber50Width of the image thumbnail in pixels.
chooseLabelstringnullLabel of the choose button. Defaults to global value in Locale configuration.
uploadLabelstringnullLabel of the upload button. Defaults to global value in Locale configuration.
cancelLabelstringnullLabel of the cancel button. Defaults to global value in Locale configuration.
chooseOptionsobject (OptionsType)nullOptions used to customize the choose button. These options have "label", "icon", "className" and "style" properties.
uploadOptionsobject (OptionsType)nullOptions used to customize the upload button. These options have "label", "icon", "className" and "style" properties.
cancelOptionsobject (OptionsType)nullOptions used to customize the cancel button. These options have "label", "icon", "className" and "style" properties.
customUploadbooleanfalseWhether to use the default upload or a manual implementation defined in uploadHandler callback.
emptyTemplateanynullThe template of empty content in the container.
progressBarTemplateanynullThe template of progressBar content in the container.
itemTemplateanynullThe template of each item content in the container.
headerTemplateanynullThe template of the header.
headerStyleobjectnullInline style of the header.
headerClassNamestringnullStyle class of the header.
contentStyleobjectnullInline style of the content.
contentClassNamestringnullStyle class of the content.
Events
NameParametersDescription
onBeforeUploadevent.xhr: XmlHttpRequest instance.
event.formData: FormData object.
Callback to invoke before file upload begins to customize the request such as post parameters before the files.
onBeforeSendevent.xhr: XmlHttpRequest instance.
event.formData: FormData object.
Callback to invoke before file send begins to customize the request such as adding headers.
onBeforeDropevent: DragEvent instance.Callback to invoke before files dropped. Return false from callback to prevent drop.
onBeforeSelectevent.originalEvent: Original browser event.
event.target.files: List of selected files.
Callback to invoke before files are selected. Return false from callback to prevent selection.
onUploadevent.xhr: XmlHttpRequest instance.
event.files: Uploaded files.
Callback to invoke when file upload is complete.
onErrorevent.xhr: XmlHttpRequest instance.
event.files: Files that are not uploaded.
Callback to invoke if file upload fails.
onClear-Callback to invoke when files in queue are removed without uploading.
onSelectevent.originalEvent: Original browser event.
event.target.files: List of selected files.
Callback to invoke when files are selected.
onProgressevent.originalEvent: Original browser event.
event.progress: Calculated progress value.
Callback to invoke when files are being uploaded.
onValidationFailfile: Invalid file.Callback to invoke when a validation file fails.
uploadHandlerevent.files: List of selected files.
event.options: Handler options.
Callback to invoke in custom upload mode to upload the files manually.
onRemoveevent.originalEvent: Original browser event.
event.file: Selected file.
Callback to invoke when a file is removed without uploading using clear button of a file.
Methods
NameParametersDescription
upload-Uploads the selected files.
clear-Clears the files list.
Styling

Following is the list of structural style classes, for theming classes visit theming page.

NameElement
p-fileuploadContainer element.
p-fileupload-buttonbarHeader containing the buttons.
p-fileupload-contentContent section.
Dependencies

None.

Component Scale

Input Style

Ripple Effect

Free Themes

Built-in component themes created by the PrimeReact Theme Designer.

Bootstrap
Blue
Purple
Blue
Purple
Material Design
Indigo
Deep Purple
Indigo
Deep Purple
Material Design Compact
Indigo
Deep Purple
Indigo
Deep Purple
Tailwind
Tailwind Light
Fluent UI
Blue
PrimeOne Design - 2022 NEW
Lara Indigo
Lara Blue
Lara Purple
Lara Teal
Lara Indigo
Lara Blue
Lara Purple
Lara Teal
PrimeOne Design - 2021
Saga Blue
Saga Green
Saga Orange
Saga Purple
Vela Blue
Vela Green
Vela Orange
Vela Purple
Arya Blue
Arya Green
Arya Orange
Arya Purple
Premium Themes

Premium themes are only available exclusively for PrimeReact Theme Designer subscribers and therefore not included in PrimeReact core.

Soho Light
Soho Dark
Viva Light
Viva Dark
Mira
Nano

Legacy Free Themes

Nova
Nova Alt
Nova Accent
Luna Blue
Luna Green
Luna Amber
Luna Pink
Rhea

Premium Create-React-App Templates

Beautifully crafted premium create-react-app application templates by the PrimeTek design team.

Sakai
Atlantis
Freya
Ultima
Diamond
Sapphire
Serenity
Babylon
Avalon
Apollo
Roma