Import and Export Indexeddb Data

I have an Epub annotation plugin where the user can annotate Epub, but the annotated text is stored in the browser in the indexeddb browser database, wants to export these annotated text to a file, and on another system I want to import this file into my indexeddb database.

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

+3
source share
1 answer

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

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

You probably won't have this problem with your application, but I just write it here for completeness ... URIs UI only work reasonably when the amount of data is small (<1 MB approximately, although this is a browser dependent). Downloadify works better with large amounts of data, but I'm still having problems with more than 5 MB of data. I'm still not sure what a good solution would be for large files than this.

+1
source

Source: https://habr.com/ru/post/1492664/


All Articles