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?

Était-ce utile?

La solution

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

Autres conseils

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 })
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top