Note: Security restrictions in Chrome prevent this example from working when the page is loaded from the file system (via file:// protocol).
- Description
- View Code
- Configuration (4)
- Methods (3)
- Events (7)
The Upload widget uses progressive enhancement to deliver the best possible uploading experience to users without requiring any extra developer effort. Upload is packed with features, including:
- Asynchronous and synchronous (on form submit) file upload
- Multiple file selection
- Removing uploaded files
- Progress tracking *
- File Drag-and-Drop *
- Cancelling upload in progress *
* These features are automatically enabled if supported by the browser.
Upload is a standards-based widget. No plug-ins required.
Getting Started
There are two primary ways to configure Upload:
- For synchronous upload using an HTML form and input
- For asynchronous upload using a simple HTML input
The async upload is implemented using the new HTML5 File API, but it will gracefully degrade and continue to function in legacy browsers (using a hidden IFRAME). If placed inside a form, queued and partially uploaded files will be sent synchronously if the async upload is submitted with the form.
Configuring for synchronous upload
1. Create a simple HTML form and input element of type "file"
<!-- Kendo will automatically set the proper FORM enctype attribute -->
<form method="post" action="handler.php">
<div>
<input name="files" id="files" type="file" />
</div>
</form>2. Initialize Upload with a jQuery selector
$(document).ready(function() {
$("#files").kendoUpload();
});It’s important to note that some type of server-side handler is needed to process and save the uploaded files. There are different server-side techniques for handling file uploads depending on the technology you use. Please consult the documentation for your server technology to understand how to implement a basic file handler.
Configure for async upload
1. Create a simple HTML input of type "file" (no HTML form is required*)
<input name="files" id="files" type="file" />2. Initialize Upload and configure async upload end-points
$("#files").kendoUpload({
async: {
saveUrl: "saveHandler.php",
removeUrl: "removeHandler.php",
autoUpload: true
}
});Like synchronous uploads, the async upload requires a server-side handler to process and save (or remove) the uploaded files. The handlers need to accept POST requests. The save action will POST the file upload to the handler (similar to synchronous uploads). The remove action will POST only the name of the file that should be removed on the server.
Both handlers should return either:
- An empty response to signify success.
- Response containing JSON string with "text/plain" content encoding. The deserialized object can be accessed in the success event handler.
- Any other response to signify error.
Configuring Upload behavior
Upload enables most behaviors by default, providing the richest experience possible depending on browser capabilities. Behaviors can be easily configured, though, using simple configuration properties. Refer to the Upload demo Configuration tab for more information on available properties.
Disable Upload default behaviors
$("#upload").kendoUpload({
multiple: false,
showFileList: false
});No code
-
disable()Disables the upload.Example
var upload = $("#upload").data("kendoUpload"); // disables the upload upload.enable(); -
enable()Enables the upload.Example
var upload = $("#upload").data("kendoUpload"); // enables the upload upload.enable(); -
toggle(enable)Toggles the upload enabled state.Example
var upload = $("#upload").data("kendoUpload"); // toggles the upload enabled state upload.toggle();Parameters
-
enable: Boolean - (Optional) The new enabled state.
-
Event data
-
files: Array - List of the files that were uploaded or removed . Each file has:
- name
- extension - the file extension inlcuding the leading dot - ".jpg", ".png", etc.
- size - the file size in bytes (null if not available)
Event data
-
files: Array - List of the files that were uploaded or removed . Each file has:
- name
- extension - the file extension inlcuding the leading dot - ".jpg", ".png", etc.
- size - the file size in bytes (null if not available)
-
operation: String - - "upload" or "remove".
-
XMLHttpRequest: Object - This is either the original XHR used for the operation or a stub containing:
- responseText
- status
- statusText
Event data
-
files: Array - List of the files that were uploaded or removed . Each file has:
- name
- extension - the file extension inlcuding the leading dot - ".jpg", ".png", etc.
- size - the file size in bytes (null if not available)
-
data: Object - - undefined by default, but can be set to a custom object to pass information to the save handler.
Event data
-
files: Array - List of the selected files. Each file has:
- name
- extension - the file extension inlcuding the leading dot - ".jpg", ".png", etc.
- size - the file size in bytes (null if not available)
Event data
-
files: Array - List of the files that were uploaded or removed . Each file has:
- name
- extension - the file extension inlcuding the leading dot - ".jpg", ".png", etc.
- size - the file size in bytes (null if not available)
-
operation: String - - "upload" or "remove".
-
response: String - - the response object returned by the server.
-
XMLHttpRequest: Object - This is either the original XHR used for the operation or a stub containing:
- responseText
- status
- statusText
Event data
-
files: Array - List of the files that will be uploaded. Each file has:
- name
- extension - the file extension inlcuding the leading dot - ".jpg", ".png", etc.
- size - the file size in bytes (null if not available)
-
data: Object - - undefined by default, but can be set to a custom object to pass information to the save handler.