I was trying to create file object with
var file = File("path/to/some/file");
as remended in the link .
However, the bellowing error occurs
Uncaught TypeError: Failed to construct 'File': Please use the 'new' operator, this DOM object constructor cannot be called as a function.
How do I fix it and link a file path to the file object in javascript?
I was trying to create file object with
var file = File("path/to/some/file");
as remended in the link https://developer.mozilla/en-US/docs/Extensions/Using_the_DOM_File_API_in_chrome_code.
However, the bellowing error occurs
Uncaught TypeError: Failed to construct 'File': Please use the 'new' operator, this DOM object constructor cannot be called as a function.
How do I fix it and link a file path to the file object in javascript?
Share Improve this question asked Jul 6, 2015 at 19:11 Elliscope FangElliscope Fang 3512 gold badges4 silver badges9 bronze badges 2- Well, did you try to use new File("..") instead ? Did it work? – Gonzalo.- Commented Jul 6, 2015 at 19:12
- 1 Are you writing chrome code for a Firefox extension? From the first three sentences of that page: "If you want to use the DOM File API in chrome code, you can do so without restriction. In fact, you get one bonus feature: you can create File objects specifying the path of the file on the user's puter. This only works from privileged code, so web content can't do it." – apsillers Commented Jul 6, 2015 at 19:38
1 Answer
Reset to default 3That's indicating that you should call the constructor like this:
var file = new File("path/to/some/file");