none
How to create a file instannce using HTML 5 file API?

    Question

  • How to create a file instance in IE environment?

    var b = newBlob(["foobarbazetcetc"], { type: "text/plain"});
    var g = newFile([b], "test.txt");   /*** this always failed****/

    It looks like IE (11) does not support calling File constructor. Similar code works with other browsers such as Chrome.

    Since File is a thin wrapper around Blog, can I write a duck typing File to replace it?

    Thanks.

    Wednesday, November 26, 2014 9:37 PM

All replies

  • Hi,

    What is the error message you get? Could you please provide your full code here?

    When you use IE9 or IE10, do you get the same result?

    As far as I know, the file object should be used like the sytax in the MSDN document.  And the  syntax is <input type="file" onchange="document.write('File name = ' + this.files[0].name)"/>.

    The Blob object represents a byte sequence similar to a  file and provides methods and properties to create or manipulate ranges of binary data. A blob can be created either using the constructor, or as a return value of the slice method.

    var blobObject = new Blob([new Uint8Array(array)], { type: 'image/png' });

    May


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, November 28, 2014 7:17 AM
    Moderator
  • The error message:
    0x800a01bd - JavaScript runtime error: Object doesn't support this action.

    Here is the source code in its entirety.

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <script>
            function myFunction() {
                var b = new Blob(["foobarbazetcetc"], { type: "text/plain" });
                var f = new File(b, "test.txt");
            }
        </script>
    </head>
    <body>
        <button type="button" onclick="myFunction()">Try it</button>
    </body>
    </html>

    Based on the w3c's File API specification, there should be a constructor for File type. However I have noticed that there is no File constructor definition in Windows' File API documentation.

    File constructor works with Chrome browser, although with a little bit different syntax. I wonder if there is special syntax to manually create a file object using File constructor in IE environment.

    I am not sure if this worked in previous IE or not though.

    Thanks.

    Friday, November 28, 2014 1:27 PM
  • Hi,

    You are right. File API in IE without a constructor for File type.

    http://msdn.microsoft.com/en-us/library/ie/hh673542(v=vs.85).aspx

     Also check this document using ActiveX object: http://www.java2s.com/Tutorial/JavaScript/0600__MS-JScript/FileSystemObjectCreateTextFile.htm

    Shu Hu


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    • Edited by Shu 2017 Tuesday, December 2, 2014 10:59 AM
    Tuesday, December 2, 2014 10:59 AM
  • Hi,

    I have tried a variety of different things of creating a pseudo File object in IE environment. Following code seems working in my limited testing scenarios:

    var b = new Blob(["foobarbazetcetc"], { type: "text/plain" });

    b.name="test.txt"

    b.lastModifiedDate= new Date();

    Now the b is a pseudo file object with all the required signature.

    It looks like that the XmlHttpRequest can happily take it as file object and upload the manually created file to server.

    Thanks for all the inputs on this issue.


     

    Thursday, December 4, 2014 3:03 PM