Get file data from input type file in IE<10

57 Views Asked by At

I'm trying to upload a pdf file via a form with a formdata, and I'm testing the functionality under the following browsers: edge and internet explorer. I use FileApi and my method works under edge and IE11 and IE10 but not under IE<10, I read that FileApi is no longer supported under IE<10. The goal is to test where the formdata can be used under internet explorer. The usefulness is to try to print a pdf file with the formdata, and that it works under edge, IE11, IE10, IE<10 as far as possible.

HTML

<body>
  
    <form name="pocform" id="pocform" enctype="multipart/form-data">
    <div class="panel-body">
    <input id="uploadfile" name="uploadfile" type="file" value="" size="60"/><br/>
    <input type="button" class="btn btn-primary" value="Upload" id="uploadButton" name="uploadButton" onclick="onClickImpression()"/>
    </div>
  </form>
</body>

JS

<script type="text/javascript">
    function onClickImpression() {
      var fileElement = document.forms[0].uploadfile.files; //works in Edge, IE11 and IE10, not in IE<10
      var file = fileElement[0];
      var formData = new FormData();
       formData.append('uploadfile', file);
       try {
        req.open("POST", url, false);
        req.send(formData);
        }
    catch (e) {
        alert(e.toString());
    }
    }
    </script> 

Is there an equivalent in IE<10 to this:

var fileElement = document.forms[0].uploadfile.files;

I try this, but not works in IE<10

document.getElementById('uploadfile').files;

Thanks.

0

There are 0 best solutions below