Mozilla: Let JavaScript scripts manipulate local files directly

Source: Internet
Author: User

A few days ago, Mozilla's Arun Ranganathan submitted a draft to the consortium to launch a JavaScript API that allows JavaScript scripts to manipulate local files directly, and Firefox's latest browser version has already provided a lot of Support, but for security reasons, the API will only provide limited access to local files.

The API introduces aFileReader 对象,可以异步加载本地文件系统中的文件,并允许开发者为诸如加载失败,进度,加载完成等事件分配回调函数,它提供的方法可以从本地文件中读取文本或二进制数据,并通过一个 abort 方法随时打断操作。

FileReader 对象使客户端的文件访问成为现实,用户不必再象以前那样首先将文件上传到服务器才能处理,事实上,IE 和 Firefox 已经拥有一些非标准的方法访问本地文件,但这些方法并非标准 JavaScript 行为。

FileReader 对象并不需要特别的权限,但出于显然的安全考虑,直接使用文件路径进行访问是不允许的,必须结合常规的 HTML file 对象,用户点击浏览之后,选择本地文件,JavaScript 再通过 DOM 引用该文件并进行操作,这个机制使得该 API 相对安全一些,因为任何本地文件的获取都需要用户的人工参与。

The following example uses the API to open a local file and display the contents of the file in a div container, and we can even addcontentEditable 属性,用户可以直接编辑文件的内容,不过,该 API 并没有提供将文件内容写回本地文件的方法,因此你编辑的内容无法保存。

As JavaScript engines become more efficient in major browsers, JavaScript can do more and more, and the introduction of local file APIs will make many interesting features a reality. Although the API is not a major technological revolution, it will broaden the horizons of Web applications and enable the Web platform to achieve more and more functionality.

This article source:Http://arstechnica.com/open-source/news/2009/11/w3c-publishes-draft-of-new-file-api-spec.ars



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.