Moiz
Moiz

Reputation: 2439

How can I check if the browser support HTML5 file upload (FormData object) after using FileAPI

Hello I have been working in AngualarJS and using File UPload control which works completely fine. Now I have used FileAPI to make that working in IE8/9.

But now I want to detect if the browser support FormData because I want to restrict only one file at a time.But as I am using FileAPI the method window.FormData === undefined is not working as because of that I get something like this in IE8 :

function(){return{append:function(a,b,c){this.data.push({key:a,val:b,name:c})},data:[],__isShim:!0}} 

How can I detect if the browser support FormData ?

Upvotes: 1

Views: 1072

Answers (1)

gkalpak
gkalpak

Reputation: 48212

Since you are using a shim and since your shim seems to return an object with a __isShim property with a value of true, you could check it like this:

var isFormDataSupported = window.FormData && !(new window.FormData()).__isShim;

Alternatively, you could check it before including your shim:

<script type="text/javascript">
    var isFormDataSupported = !!window.FormData;
</script>
<script src="src/to/your/shim.js"></script>

Upvotes: 2

Related Questions