Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

166
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda