This article mainly introduces the relevant information on the file upload function based on Ajax and HTML5 in MVC. Friends in need can refer to the following
Introduction
In actual practice In programming, we often encounter the function of uploading files and displaying the upload progress. For this purpose, this article will introduce to you how to implement the file upload function with progress display without using flash or any plug-in for uploading files.
Basic function: realize file upload function with progress bar
Advanced function: realize multiple file upload function by dragging and dropping files
Background
HTML5 provides a standard method of accessing local files - the File API specification. File information can be accessed by calling the File API, and the client can also be used to verify the type and size of the uploaded file. specification.
This specification includes the following interfaces to use files:
File interface: has the "read permission" of the file and can obtain the file name, type, size, etc.
FileList interface: refers to a list of individually selected files, which can be presented to the user interface for user selection through or drag and drop.
XMLHTTPRequest2 is the unsung hero of HTML5. XHR2 is roughly the same as XMLHttpRequest, but it also adds many new features, as follows:
1. Added upload/download binary data
2. Added the Progress (progress bar) event during the upload process, which contains multiple parts of information:
Total: Integer value, used to specify the total number of bytes of transmitted data.
Loaded: Integer value, used to specify the uploaded bytes.
lengthComputable: Bool value is used to detect whether the uploaded file size is computable.
3. Cross-resource sharing request
These new features make Ajax and HTML5 work well together, making file uploading very simple, without the need to use Flash Player, external plug-ins or html The