AKASHAorg / secure-webstore

A secure IndexedDB store with built-in encryption
MIT License
44 stars 6 forks source link

Blob question #23

Closed dannycabrera closed 1 year ago

dannycabrera commented 1 year ago

Hi Guys,

Thank you for a great library. Having some trouble with blobs and wondering anyone can point me in the right direction. I am creating a valid blob that can be played via HTML5 audio tag using URL.createObjectURL(). The issue I am having is that when I store the blob and then get() it, the object returned is not a blob. Wondering if blobs need to be handled differently in any way? I can set() a string "json" and get() it just fine, issue is only with blobs.

let blob = new Blob(chunks, { 'type': mimeType });

store.set(id, blob)
  .then(() => console.log('Audio saved!'))
  .catch(err => console.log('Audio save failed!', err))

store.get(id).then((data) => {
    // data returned is Object but not a valid blob
})

Thanks

deiu commented 1 year ago

Hi @dannycabrera. Browsers' local storage support is a bit limiting. It was never meant to be used to store byte blobs, which is what you want to do. The best solution I can suggest is to encode your blob to a base64 representation and store that instead.

dannycabrera commented 1 year ago

Hi @deiu, appreciate the response. Base64 works fine, guess I was thrown off by the wording "Since this is IDB-backed, you can store anything structured-clonable (numbers, arrays, objects, dates, blobs etc).", assumed any blob would work. Thanks