If XHR2 is supported with file-upload capabilites, my application needs to do different preparation. What is a safe way to check if these capabilities are supported. Is it sufficient, for example, to just check an XMLHttpRequest
(or MS equivalents) for the upload
property? like...
var xhr = new XMLHttpRequest();
if (typeof xhr.upload !== "undefined") {
do nice stuff
}
else {
do oldschool stuff
}
Or is this not safe?
Create the form object for submissionCreate form data that would be submitted in the POST request to /upload. The formData will contain the file object which can be easily appended. Then an AJAX request can be created by using XMLHttpRequest() method.
The XMLHttpRequest upload property returns an XMLHttpRequestUpload object that can be observed to monitor an upload's progress. It is an opaque object, but because it's also an XMLHttpRequestEventTarget , event listeners can be attached to track its process.
if (new XMLHttpRequest().upload) { // welcome home! } else { // not supported }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With