简体   繁体   English

HTML5 Filesystems API - 让用户将文件保存到其实际文件系统

[英]HTML5 Filesystems API - Letting Users Save Files to Their Actual Filesystem

I am aware that the HTML5 Filesystem API gives you access to a sandboxed file system. 我知道HTML5 Filesystem API允许您访问沙盒文件系统。 Let's say I write a file to the filesystem. 假设我将文件写入文件系统。 Is it possible to let the user save that file to their actual file system? 是否可以让用户将该文件保存到实际的文件系统中? I would like to be able to tell the user where the file is written so that they may access it but that does not seem to be possible. 我希望能够告诉用户文件的写入位置,以便他们可以访问它,但这似乎是不可能的。

My only idea is to read the file as a data url and make a hyperlink that the user can save, but that has scalability issues in terms of file size. 我唯一的想法是将文件作为数据URL读取并创建用户可以保存的超链接,但是在文件大小方面存在可伸缩性问题。

You can use the URL obtained from the toURL method as the value for a link's href attribute, which link in addition has a download attribute. 您可以使用从toURL方法获取的URL作为链接的href属性的值,该链接另外还具有download属性。 Clicking on the link will then prompt the user to save the contents on her filesystem. 单击该链接将提示用户将内容保存在她的文件系统中。

Quoting MDN - Basic Concepts About the Filesystem API : 引用MDN - 关于Filesystem API的基本概念

You can, however, export a file from a web app to a desktop app. 但是,您可以将文件从Web应用程序导出到桌面应用程序。 For example, you can use the File API, create a blob, redirect an iframe to the blob, and invoke the download manager. 例如,您可以使用File API,创建blob,将iframe重定向到blob,然后调用下载管理器。

Also, the very page I linked to before discusses FileEntry 's toURL() method which returns a url in the form of filesystem: . 此外, 我之前链接的页面讨论了FileEntrytoURL()方法,它以filesystem:的形式返回一个url filesystem: .

Here is another article on how to make the browser download a file from a url. 这是另一篇关于如何让浏览器从网址下载文件的文章。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM