Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

167
Vistas
Load Image/Video from IndexedDB

I am working on a PWA project where I have created an IndexedDB and stored the images and videos in it. On the next reload of page, if image/video is available in IndexedDB, it should load it from there.

function fetchMedia(id) {
    var transaction = db.transaction(["media"]);
    var objectStore = transaction.objectStore("media");
    var request = objectStore.get(id);

    request.onerror = function(event) {
       console.log("Unable to retrieve daa from database!");
       return "";
    };

   request.onsuccess = function(event) {
       var imgFile = request.result;
       console.log(imgFile)
       var imgURL = window.URL.createObjectURL(imgFile);
       return imgURL;
   };
}

It always returns undefined. When I console.log the imgFile, it shows that it's there in the IndexedDB:

enter image description here

File in IndexedDB:

enter image description here

I have also tried this but no success yet:

var imgURL = window.URL.createObjectURL(new Blob(imgFile, {'type': 'application/octet-stream'}));

What's the correct approach to load the files from IndexedDB?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If your screenshot is accurate, then request.result is not an image, it's an object {id: '13388-7247-6247-62584', file: Blob, ...}. You didn't just store the image file, you wrapped it in an object. So what you're getting back out is an object.

Try imgFile = request.result.file; instead.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda