How to instantiate a File object in JavaScript?

According to the W3C File API specification, the File constructor requires 2 (or 3) parameters.

So to create a empty file do:

var f = new File([""], "filename");
  • The first argument is the data provided as an array of lines of text;
  • The second argument is the filename ;
  • The third argument looks like:var f = new File([""], "filename.txt", {type: "text/plain", lastModified: date})

It works in FireFox, Chrome and Opera, but not in Safari or IE/Edge.

Leave a Comment