Search code examples
javascriptajaxfile-uploadxmlhttprequestbrowser-support

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?


Solution

  • if (new XMLHttpRequest().upload) {
      // welcome home!
    } else {
      // not supported
    }