可以使用 HTML5 本地存储来存储文件吗?如果没有,怎么办?
如何通过浏览器机制(插件是可接受的解决方案)在用户计算机上缓存/管理许多大文件(视频)。据我所知,本地存储是关于数据库类型的数据,而不是文件。
How would one go about caching / managing many large files (videos) on a user's computer via browser mechanisms (plugins are acceptable solutions). From what I can tell, local storage is about database type data, not files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
FileSystem API[1,2] 将是您未来最好的选择,在某一时刻它是非常前沿的。然而它已经被w3c放弃了。来自他们自己的文档:
The FileSystem API[1,2] was going to be your best bet going forward, at one point it was very much bleeding edge. However it has been been abandoned by w3c. From their own documentation:
正如其他人所说,HTML5 文件系统 API 已死。 IndexedDB 似乎是另一个选择。请参阅此处。
HTML5 FileSystem API is dead as others have said. IndexedDB seems to be the other option. See here.
这个问题的答案取决于您对以下问题的回答:
如果您对上述所有问题的回答都是“是”,则使用 文件,FileWriter 和 文件系统 API,您可以从浏览器选项卡/窗口的上下文中读取和写入文件使用 JavaScript。
以下是如何直接和间接使用 API 来完成这些操作的简单示例:
BakedGoods*
写入文件:
读取文件:
使用原始文件、FileWriter 和 FileSystem API
写入文件:
读取文件:
因为您也对非本机开放(基于插件的)解决方案,您可以在 IsolatedStorage,通过 Silverlight 提供对其的访问。
isolatedStorage在很多方面与FileSystem类似,特别是它也存在于沙箱中并使用虚拟文件系统。但是,托管代码 需要使用该设施;需要编写此类代码的解决方案超出了本问题的范围。
当然,一种利用互补托管代码、只需要编写 Javascript 的解决方案完全在这个问题的范围内;) :
*BakedGoods 正是由这里的这个人维护的:)< /em>
The answer to this question depends on your answers to the following questions:
If you answered "yes" to all of the above, then with the File, FileWriter and FileSystem APIs, you can read and write files from the context of a browser tab/window using Javascript.
Here are simple examples of how the APIs are used, directly and indirectly, in tandem to do these things:
BakedGoods*
Write file:
Read file:
Using the raw File, FileWriter, and FileSystem APIs
Write file:
Read file:
Since you're also open to non-native (plug-in based) solutions, you can take advantage of file i/o enabled by Silverlight in IsolatedStorage, access to which is provided through Silverlight.
IsolatedStorage is similar in many aspects to FileSystem, in particular it also exists in a sandbox and makes use of a virtual file system. However, managed code is required to utilize this facility; a solution which requires writing such code is beyond the scope of this question.
Of course, a solution which makes use of complementary managed code, leaving one with only Javascript to write, is well within the scope of this question ;) :
*BakedGoods is maintained by none other than this guy right here :)
FSO.js 将为您包装 HTML5 文件系统 API,使存储、管理和操作大型数据集变得非常容易沙盒文件系统中的文件。
FSO.js will wrap the HTML5 FileSystem API for you, making it really easy to store, manage, and manipulate sets of large files in a sandboxed File System.
目前,在大多数实现中,HTML5 本地存储默认限制为 5MB。我认为你不能在那里存储很多视频。
资料来源: https://web.archive.org/web /20120714114208/http://diveintohtml5.info/storage.html
HTML5 local storage is currently limited to 5MB by default in most implementations. I don't think you can store a lot of video in there.
Source: https://web.archive.org/web/20120714114208/http://diveintohtml5.info/storage.html
上面已经解释了 html5 本地存储的大部分内容。
这里https://stackoverflow.com/a/11272187/1460465有一个类似的问题,不是关于视频的,而是如果你可以将xml添加到本地存储。
我在文章 javascript is used to parse an xml to local storage and how to query it offline 中提到了我的回答中的一篇文章。
可能对你有帮助。
Well most parts of html5 local storage are explained above.
here https://stackoverflow.com/a/11272187/1460465 there was a similar question, not about videos but if you can add an xml to local storage.
I mentioned an article in my answer in the article javascript is used to parse an xml to local storage and how to query it offline.
Might help you.