My answer is rather late, but here it is:
Short answer:
XMLHttpRequest is the best way to upload files to a modern browser.
What is XMLHttpRequest?
XMLHttpRequest is a JavaScript object that was developed by Microsoft and adopted by Mozilla, Apple and Google. Now it is standardized in W3C . It provides an easy way to retrieve data from a URL without the need for a full page refresh. A web page can only refresh part of the page without violating what the user is doing. XMLHttpRequest is used in AJAX .
Despite its name, XMLHttpRequest can be used to retrieve any type of data, not just XML , and supports protocols other than HTTP (including file and ftp ).
The XMLHttpRequest object received a facelift in the Html5 specifications. In particular, XMLHttpRequest Level 2 .
Benefits:
- Handling byte streams such as File , Blob and FormData strong> objects to upload and download
- Run Events on Download and Download
- Cross Start Requests
- Allow creation of anonymous request - this is not sending HTTP Referer
- Ability to set timeout for request
- Download takes place in the background
- The page the user is on remains intact
- No changes are required on the server side , so the existing logic on the server side should not remain unchanged, which greatly facilitates the adaptation of this technology.
Html5 progress event:
According to the Html5 Progress Events spec , the Html5 progress event provides, among other things, the following information:
total - Total bytes being transferred loaded - Bytes uploaded thus far lengthComputable - Specifies if the total size of the data/file being uploaded is known
Using the above information, it is quite easy to provide the user with information about the time remaining until the end.
Report this to the user:
Information about the file that can be provided to the user:
- File name
- file size
- Type mime
- Progress bar with percent complete.
- Download speed or bandwidth.
- Estimated Time Left
- Bytes loaded so far
- Server response
Download Files Using XMLHttpRequest Demo
Please check " Uploading Files Using Html5 with Progress Demonstration " for an example. All JavaScript code is needed on the page, but CSS is not included. For security reasons, file types are limited to jpg, png, gif, and txt. The maximum file size is 2 MB.
XMLHttpRequest Browser Compatibility:

Pedro Lobito Apr 25 '15 at 19:28 2015-04-25 19:28
source share