Question

It is possible to store blobs and arraybuffers in indexedDB (as you can see here). My problem is, that I am storing pdf files in the storage and want to "download" them when the user clicks on a specific link. Is it possible to "download" files from the local indexDB database?

Was it helpful?

Solution

This is not possible using native JavaScript or the IndexedDB API, but check out FileWriter and BlobBuilder parts of the upcoming Filesystem API.

OTHER TIPS

This questions isn't really IndexedDB related, but rather simply "How do I get the user to save a Blob object". A Blob works the same way, no matter if you've loaded it from IndexedDB or if you got it from somewhere else.

Using a FileSaver would be the best solution, had it been consistently implemented, but it's not.

What should work is to do something like this:

var iframe = document.createElement("iframe");
document.body.appendChild(iframe);
var url = URL.createObjectURL(blob); // This is the magic!
iframe.src = url;

It is now possible to save Blobs in indexedDb

objectStore.put({ id: idValue, blobdata: data })
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top