gpt4 book ai didi

javascript - 在浏览器的本地存储中存储对磁盘上文件的引用

转载 作者:行者123 更新时间:2023-11-30 06:52:47 25 4
gpt4 key购买 nike

似乎对于当前的文件 API,访问以前添加的文件的唯一方法是将整个文件对象存储在本地存储中。当添加多个文件时,这会很快消耗浏览器内存。

我想知道是否有一种方法可以只在本地存储中存储对文件的某种类型的引用,并能够通过其引用访问该文件。

我尝试使用 URL.createObjectURL 函数为文件生成 URL,但该 URL 与文档相关联,并在页面重新加载时过期。是否存在任何替代方案?

最佳答案

通过“快速吃掉浏览器的内存”,我假设你的意思是你的 LocalStorage 配额被你存储在那里的文件用完了。本地存储配额是为了防止网站占用过多用户的本地磁盘空间。默认情况下,大多数浏览器将每个域的存储空间限制为 5MB。

From the w3 spec ,本地存储配额实际上是一种功能,可以防止您所要求的事情发生(即网站在用户磁盘上存储的文件多于用户允许的配额):

User agents should limit the total amount of space allowed for storage areas, because hostile authors could otherwise use this feature to exhaust the user's available disk space.

User agents should guard against sites storing data under their origin's other affiliated sites, e.g. storing up to the limit in a1.example.com, a2.example.com, a3.example.com, etc, circumventing the main example.com storage limit.

User agents may prompt the user when quotas are reached, allowing the user to grant a site more space. This enables sites to store many user-created documents on the user's computer, for instance.

关于javascript - 在浏览器的本地存储中存储对磁盘上文件的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32150559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com