Now most of browsers are supporting IndexedDB to store data/file directly as File, Blob or ArrayBuffer.
This code save
I recommend using Blob for images & videos as the API is fairly straightforward for downloading as blob and saving to db, as well as retrieving from db and creating URL for src attribute
Check this sample here for implementation https://hacks.mozilla.org/2012/02/storing-images-and-files-in-indexeddb/