JavaScript/jQuery FileUploader Options
abortUpload
A Promise that is resolved after the upload is aborted. It is a native Promise or a jQuery.Promise when you use jQuery.
accept
The value of this property is passed to the accept attribute of the underlying input element. Thus, the property accepts a MIME type or several types separated by a comma. Refer to the input element documentation for information on available values.
Note that the allowedFileExtensions property disables the uploading of the prohibited file types, but does not restrict these file types in the Open File dialog. To filter file types in the Open File dialog, use the accept
option.
accessKey
The value of this property will be passed to the accesskey
attribute of the HTML element that underlies the UI component.
activeStateEnabled
The UI component switches to the active state when users press down the primary mouse button. When this property is set to true, the CSS rules for the active state apply. You can change these rules to customize the component.
Use this property when you display the component on a platform whose guidelines include the active state change for UI components.
allowCanceling
If this property is set to true, a cancel button is displayed for each selected file.
chunkSize
Specifies the chunk size in bytes. Applies only if uploadMode is "instantly" or "useButtons". Requires a server that can process file chunks.
Set this property to a positive value to enable chunk upload. The UI component should be configured as described in the Chunk Upload article. When chunk upload is enabled, the FileUploader sends several multipart/form-data requests with information about the file and chunk. The "chunkMetadata" parameter contains chunk details as a JSON object of the following structure:
- {
- "FileGuid": string,
- "FileName": string,
- "FileType": string,
- "FileSize": long,
- "Index": long, // The chunk's index
- "TotalCount": long, // The file's total chunk count
- }
See Also
dialogTrigger
This property accepts one of the following values:
A CSS selector, or a jQuery selector if you use jQuery
index.js- $(function(){
- $("#fileUploaderContainer").dxFileUploader({
- // ...
- dialogTrigger: '.open-button'
- });
- });
A jQuery wrapper
index.js- $(function(){
- $("#fileUploaderContainer").dxFileUploader({
- // ...
- dialogTrigger: $('.open-button')
- });
- });
A DOM element
index.js- $(function(){
- $("#fileUploaderContainer").dxFileUploader({
- // ...
- dialogTrigger: document.querySelector('.open-button')
- });
- });
dropZone
This property accepts one of the following values:
A CSS selector, or a jQuery selector if you use jQuery
index.js- $(function(){
- $("#fileUploaderContainer").dxFileUploader({
- // ...
- dropZone: '.test-div'
- });
- });
A jQuery wrapper
index.js- $(function(){
- $("#fileUploaderContainer").dxFileUploader({
- // ...
- dropZone: $('.test-div')
- });
- });
A DOM element
index.js- $(function(){
- $("#fileUploaderContainer").dxFileUploader({
- // ...
- dropZone: document.querySelector('.test-div')
- });
- });
See Also
elementAttr
Specifies the global attributes to be attached to the UI component's container element.
height
This property accepts a value of one of the following types:
Number
The height in pixels.String
A CSS-accepted measurement of height. For example,"55px"
,"20vh"
,"80%"
,"inherit"
.Function (deprecated since v21.2)
Refer to the W0017 warning description for information on how you can migrate to viewport units.
hoverStateEnabled
Specifies whether the FileUploader component changes the state of all its buttons when users hover over them.
invalidFileExtensionMessage
The text displayed when the extension of the file being uploaded is not an allowed file extension.
invalidMaxFileSizeMessage
The text displayed when the size of the file being uploaded is greater than the maxFileSize.
invalidMinFileSizeMessage
The text displayed when the size of the file being uploaded is less than the minFileSize.
isDirty
This property is a read-only flag. You can use it to check if the editor value changed.
- $(() => {
- const fileUploader = $('#fileUploader').dxFileUploader({
- // ...
- }).dxFileUploader('instance');
- $('#button').dxButton({
- // ...
- onClick () {
- if (fileUploader.option('isDirty')) {
- DevExpress.ui.notify("Do not forget to save changes", "warning", 500);
- }
- }
- });
- });
See Also
isValid
The FileUploader provides alternative validation properties: maxFileSize, minFileSize, and allowedFileExtensions.
maxFileSize
Specifies the maximum file size (in bytes) allowed for uploading. Applies only if uploadMode is "instantly" or "useButtons".
minFileSize
Specifies the minimum file size (in bytes) allowed for uploading. Applies only if uploadMode is "instantly" or "useButtons".
name
Specifies the value passed to the name attribute of the underlying input element. Required to access uploaded files on the server.
See Also
onBeforeSend
Name | Type | Description |
---|---|---|
component |
The UI component's instance. |
|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
file |
An uploaded file. |
|
request |
An XMLHttpRequest for the file. |
|
uploadInfo |
An object that provides information about the file upload session. |
onContentReady
A function that is executed when the UI component is rendered and each time the component is repainted.
Name | Type | Description |
---|---|---|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
component |
The UI component's instance. |
onDisposing
A function that is executed before the UI component is disposed of.
Name | Type | Description |
---|---|---|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
component |
The UI component's instance. |
onDropZoneEnter
Name | Type | Description |
---|---|---|
component |
The UI component's instance. |
|
dropZoneElement |
A drop zone element. |
|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
event | Event (jQuery or EventObject) |
The event that caused the function to execute. It is an EventObject or a jQuery.Event when you use jQuery. |
onDropZoneLeave
Name | Type | Description |
---|---|---|
component |
The UI component's instance. |
|
dropZoneElement |
A drop zone element. |
|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
event | Event (jQuery or EventObject) |
The event that caused the function to execute. It is an EventObject or a jQuery.Event when you use jQuery. |
onFilesUploaded
Name | Type | Description |
---|---|---|
component |
The UI component's instance. |
|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
onInitialized
Name | Type | Description |
---|---|---|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
component |
The UI component's instance. |
onOptionChanged
Name | Type | Description |
---|---|---|
value | any |
The modified property's new value. |
previousValue | any |
The UI component's previous value. |
name |
The modified property if it belongs to the first level. Otherwise, the first-level property it is nested into. |
|
fullName |
The path to the modified property that includes all parent properties. |
|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
component |
The UI component's instance. |
onProgress
Name | Type | Description |
---|---|---|
bytesLoaded |
The total count of the uploaded bytes. |
|
bytesTotal |
The total count of bytes in the XMLHttpRequest. |
|
component |
The UI component's instance. |
|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
event | Event (jQuery or EventObject) |
The event that caused the function to execute. It is an EventObject or a jQuery.Event when you use jQuery. |
file |
An uploaded file. |
|
request |
An XMLHttpRequest for the file. |
|
segmentSize |
The size of the uploaded file segment. |
Note that the onProgress
function is not in effect if you use FileUploader in useForm
upload mode or call the form.submit method.
onUploadAborted
Name | Type | Description |
---|---|---|
component |
The UI component's instance. |
|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
event | Event (jQuery or EventObject) |
The event that caused the function to execute. It is an EventObject or a jQuery.Event when you use jQuery. |
file |
The uploaded file. |
|
message |
The message displayed by the UI component when the file upload is cancelled. |
|
request |
Specifies an XMLHttpRequest for the file. |
onUploaded
Name | Type | Description |
---|---|---|
component |
The UI component's instance. |
|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
event | Event (jQuery or EventObject) |
The event that caused the function to execute. It is an EventObject or a jQuery.Event when you use jQuery. |
file |
The uploaded file. |
|
message |
The message displayed by the UI component when uploading is finished. |
|
request |
Specifies an XMLHttpRequest for the file. |
Note that the onUploaded
function is not in effect if you use FileUploader in useForm
upload mode or call the form.submit method.
See Also
onUploadError
Name | Type | Description |
---|---|---|
component |
The UI component's instance. |
|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
error | any |
The error that occurred. |
event | Event (jQuery or EventObject) |
The event that caused the function to execute. It is an EventObject or a jQuery.Event when you use jQuery. |
file |
The uploaded file. |
|
message |
The message displayed by the UI component on uploading failure. |
|
request |
Specifies an XMLHttpRequest for the file. |
onUploadStarted
Name | Type | Description |
---|---|---|
component |
The UI component's instance. |
|
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
event | Event (jQuery or EventObject) |
The event that caused the function to execute. It is an EventObject or a jQuery.Event when you use jQuery. |
file |
The uploaded file. |
|
request |
Specifies an XMLHttpRequest for the file. |
Note that the onUploadStarted
function is not in effect if you use FileUploader in useForm
upload mode or call the form.submit method.
onValueChanged
Name | Type | Description |
---|---|---|
value |
Newly selected files. |
|
previousValue |
Previously selected files. |
|
event | Event (jQuery or EventObject) |
The event that caused the function to execute. It is an EventObject or a jQuery.Event when you use jQuery. This field is undefined if the value is changed programmatically. |
element |
The UI component's container. It is an HTML Element or a jQuery Element when you use jQuery. |
|
component |
The UI component's instance. |
The following code snippet demonstrates how to add image previews before uploading. It uses File API to get image details and create a thumbnail.
- <div id="fileUploader"></div>
- <div id="list">
- $(function () {
- function previewImages(file) {
- const reader = new FileReader();
- reader.onload = (function (theFile) {
- return function (e) {
- const span = $("<span>");
- span.html(
- [
- '<img class="thumb" src="',
- e.target.result,
- '" title="',
- escape(theFile.name),
- '"/>'
- ].join("")
- );
- $("#list").append(span);
- };
- })(file);
- reader.readAsDataURL(file);
- }
- const fileUploader = $("#fileUploader").dxFileUploader({
- accept: "image/*",
- uploadMode: "useButtons",
- multiple: true,
- onValueChanged: function (args) {
- const files = args.value;
- $("#list").html("");
- if (files.length == 0) return;
- for (let i = 0; i < files.length; i+=1) {
- const file = files[i];
- previewImages(file);
- }
- }
- }).dxFileUploader("instance");
- });
- .thumb {
- height: 150px;
- max-width: 150px;
- border: 1px solid #000;
- margin: 10px 5px 0 0;
- }
For details on how to retrieve file data after uploading, refer to the following demo:
readOnly
Set the readOnly property to true to enable the following functionality:
- File upload in UI is disabled. This also includes a HTML element specified in the dialogTrigger property.
- Built-in action buttons are disabled.
Note that already selected files are available for upload in readOnly mode.
readyToUploadMessage
This property makes sense only if the uploadMode property is set to "useButtons".
rtlEnabled
When this property is set to true, the UI component text flows from right to left, and the layout of elements is reversed. To switch the entire application/site to the right-to-left representation, assign true to the rtlEnabled field of the object passed to the DevExpress.config(config) method.
- DevExpress.config({
- rtlEnabled: true
- });
tabIndex
The value of this property will be passed to the tabindex
attribute of the HTML element that underlies the UI component.
uploadAbortedMessage
This property is only available if the uploadMode property is set to "instantly".
uploadButtonText
The property makes sense only if the uploadMode property is set to "useButtons" or "instantly".
uploadChunk
A Promise that is resolved after the chunk is uploaded. It is a native Promise or a jQuery.Promise when you use jQuery.
uploadedMessage
The property makes sense only if the uploadMode property is set to "useButtons" or "instantly".
uploadFailedMessage
The property makes sense only if the uploadMode property is set to "useButtons" or "instantly".
uploadFile
A Promise that is resolved after the file is uploaded. It is a native Promise or a jQuery.Promise when you use jQuery.
A Promise that is resolved after the file is uploaded. It is a native Promise or a jQuery.Promise when you use jQuery.
uploadMethod
The property makes sense only if the uploadMode property is set to "useButtons" or "instantly".
uploadMode
Depending on the uploadMode, the FileUploader UI component uses an HTML form or a FormData interface with a series of Ajax requests to upload files. The uploadMode property accepts one of the following values:
"instantly" (default)
Ajax upload. Files are uploaded after they are selected."useButtons"
Ajax upload. Files are uploaded after a user clicks the Upload button."useForm"
HTML form upload. Files are uploaded when the HTML form is submitted.
See Also
uploadUrl
The property makes sense only if the uploadMode property is set to "useButtons" or "instantly".
validationError
Information on the broken validation rule. Contains the first item from the validationErrors array.
validationStatus
The following table illustrates the validation status indicators:
validationStatus | Indicator |
---|---|
"pending" |
![]() |
"valid" |
![]() |
"invalid" |
![]() |
When you assign "invalid" to validationStatus, you can also use the validationErrors array to set an error message as shown below:
- $(function() {
- const fileUploader = $("#fileUploaderContainer").dxFileUploader({
- // ...
- }).dxFileUploader("instance");
- function setInvalidStatus(message) {
- fileUploader.option({
- validationStatus: "invalid",
- validationErrors: [{ message: message }]
- });
- }
- });
value
Specifies a File instance representing the selected file. Read-only when uploadMode is "useForm".
width
This property accepts a value of one of the following types:
Number
The width in pixels.String
A CSS-accepted measurement of width. For example,"55px"
,"20vw"
,"80%"
,"auto"
,"inherit"
.Function (deprecated since v21.2)
Refer to the W0017 warning description for information on how you can migrate to viewport units.