导入和导出Indexeddb数据 [英] Import and Export Indexeddb data

查看:620
本文介绍了导入和导出Indexeddb数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Epub注释插件,用户可以在其中注释Epub,但是注释的文本存储在浏览器的indexeddb数据库中的浏览器中,想要将这些注释的文本导出到文件中,而在其他系统中,我想将这些文件导入到我的indexeddb数据库.

I have an Epub annotation plugin where user can annotate the Epub, but the annotated text is stored in the browser in browser's indexeddb database, want to export those annotated text to an file and in other system i want to import those file to my indexeddb database.

我该怎么做,任何人都可以提出一些想法以及一些URLS,示例和代码.

How can I do this , can any one suggest any idea along with some URLS , examples, code.

推荐答案

您可以将任何内容作为JavaScript对象从IndexedDB数据库中获取.然后,您可以使用JSON.stringify将其转换为JSON字符串.然后,您可以使用数据URI 将其转换为可下载文件.在我的一个项目中,我做了类似的事情.您可以看到git diff 此处.

You can get anything out of an IndexedDB database as a JavaScript object. Then you can use JSON.stringify to turn it into a JSON string. Then you can turn that into a downloadable file by using data URIs. I did something like this in one of my projects; you can see the git diff here.

对于导入,您可以只接受一个JSON文件,将其解析,然后将其添加到数据库中.

For import, you can just accept a JSON file, parse it, and add it to the database.

您的应用程序可能不会出现这个问题,但是为了完整性起见,我只是在这里写它……数据URI仅在数据量较小时(大约是<1 MB,尽管是浏览器)才能合理地执行取决于). Downloadify 在处理大量数据时表现更好,但是我仍然遇到了超过5MB的数据麻烦.我仍然不确定对于比这个更大的文件,什么是好的解决方案.

You probably won't have this problem with your application, but I'm just writing it here for completeness... Data URIs only perform reasonably when the amount of data is small (< 1 MB roughly, although it's browser dependent). Downloadify performs better with large amounts of data, but I still ran into trouble with more than ~5MB of data. I'm still not sure what a good solution would be for larger files than that.

这篇关于导入和导出Indexeddb数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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