最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Uncaught TypeError: Failed to construct 'File': Please use the 'new' operator, this

programmeradmin2浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 3

That's indicating that you should call the constructor like this:

var file = new File("path/to/some/file");

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论