使用IndexedDB检测可用存储 [英] Detecting Available Storage with IndexedDB

查看:145
本文介绍了使用IndexedDB检测可用存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个离线应用程序,利用IDB存储通常存在于MySQL数据库中的图像和文本供离线使用。

I have written an offline application that utilises IDB to store images and text that would normally exist in a MySQL DB for offline use.

但是,我正在尝试找出一种方法,我可以读取IndexedDB的设备存储限制。我目前正在使用以下方法来确定这一点,尽管它只适用于Chrome。

However, I am trying to figure out a way that I can read the limit on the devices storage for IndexedDB. I am currently using the following method to determine this although it only works in Chrome.

我正在使用此处的代码段 https://stackoverflow.com/ a / 18350531/4121257 获取基于WebKit的 storageInfo ,但是如果有人知道如何在FF& IE&更具体地说,Safari会很棒。

I am using the snippet from here https://stackoverflow.com/a/18350531/4121257 which gets the storageInfo for WebKit based however if someone knows a way to get it on FF & IE & more specifically Safari that would be great.

从我收集到的内容中,这将返回该浏览器为域而不仅仅是IDB存储的所有内容的使用配额。但是,我使用的是重新配额。从这里我要么向服务器执行一个AJAX请求,以获得将要存储的所有文件的估计大小,如果有足够的存储空间,我将计算出来,或者我将计算存储在IDB中的ammount,并确定是否有足够的存储更多。

From what I have gathered this returns the used quota for everything stored by that browser for the domain not just IDB. However, what I am using is the remaning quota. From this I either perform an AJAX request to the server to get the estimated size of all the files that will be stored and work out if there is enough storage or I will calculate the ammount stored in the IDB and work out if there is enough to store more.

我想知道是否有人采用了更加精简的方法?还有一种方法来检查FF / IE中的重新配额,尤其是Safari&甚至是一种特别检查IDB配额的方法。

I was wondering if someone had a more 'streamlined' approach? And a way to check the remaning quota in FF/IE and especially Safari & even a way to check quota for IDB specifically.

推荐答案

目前唯一可用于Chrome的API是 navigator.webkitTemporaryStorage.queryUsageAndQuota()

The only API that is currently available and only for chrome is navigator.webkitTemporaryStorage.queryUsageAndQuota().

Firefox 计划实施此API。

Firefox had plans to implement this API too.

还有两个实验API navigator.storageQuota.queryInfo(type) navigator.storage.estimate()如果你运行chrome with - 使能的实验-网络的平台的功能。更多详细信息: https://groups.google.com/a/chromium.org/forum/#!searchin/blink-dev/quota-api/blink-dev/P6eY26vB91c/Ri4ohXOPBQAJ

There are also two experimental APIs navigator.storageQuota.queryInfo(type) and navigator.storage.estimate() available if you run chrome with --enable-experimental-web-platform-features. More details here: https://groups.google.com/a/chromium.org/forum/#!searchin/blink-dev/quota-api/blink-dev/P6eY26vB91c/Ri4ohXOPBQAJ

我认为存储配额估算()API 是最有趣的一个。它仍然是草稿,但 chrome mozilla 目前正在实施此API。

I think the Storage quota estimate() API is the most interesting one. It is still a draft but chrome and mozilla are currently implementing this API.

很遗憾目前还没有公开信息何时以及如果 Edge 和Safari将实现此API。

Unfortunately there is currently no public info available when and if Edge and Safari will implement this API.


Edge目前有一个非常不同的配额模型 - 而不是全源限制,每个存储type(索引db,本地存储等)有自己的限制。

Edge currently has a very different model for quota - rather than a whole-origin limit, each storage type (indexed db, local storage, etc) has its own limit.

更新:此功能是添加到Chrome 52(实验标记)和Firefox 51(每晚)
navigator.storage.estimate()。then((data)=> console.log(data))// Object {quota:2147483648,用法:0}

Update: This feature was added to Chrome 52 (experimental flag) and Firefox 51 (nightly) navigator.storage.estimate().then((data)=>console.log(data)) // Object { quota: 2147483648, usage: 0 }

这篇关于使用IndexedDB检测可用存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆