Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to check for XHR2 file upload support?

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?

like image 687
rewolf Avatar asked Jul 20 '11 20:07

rewolf


People also ask

How do I upload a file using XMLHttpRequest?

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.

What is XHR upload?

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.


1 Answers

if (new XMLHttpRequest().upload) {   // welcome home! } else {   // not supported } 
like image 109
Pono Avatar answered Oct 10 '22 20:10

Pono