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

745
Visualizações
Vue display an image from firebase cloud storage blob

Im building a product lookup repository, users will scan a product barcode which will then return data about the product and a picture of the product to be displayed.

Right now for testing purposes I have set up a firebase storage bucket, with one image uploaded. Im have successfully been able to retrieve the image by calling the firebase storage api, but I cant seem to display it in my Vue app. I cant seem to find the proper documentation for this on firebase docs, as their example uses plain js and html.

My code to display the image:

<template>
  <div class="container">
    <div class="row">
      <div class="col">
        <image v-if="image!==null" :src="image"></image>
      </div>
    </div>
  </div>
</template>

The script that runs when the page is mounted and it will get the image from the storage bucket and display it.

<script>
import firebase from "firebase";
export default {
  name: "ProductPage",
  data: () => {
    return {
      image: null
    };
  },
  mounted() {
    firebase
      .storage()
      .ref("test/1234-1.jpg")
      .getDownloadURL()
      .then(url => {
        const xhr = new XMLHttpRequest();
        xhr.responseType = "blob";
        xhr.onload = event => {
          this.image = xhr.response;
          event.preventDefault();
        };
        xhr.open("GET", url);
        xhr.send();
      })
      .catch(error => {
        // Handle any errors
        console.log(error);
      });
  }
};
</script>

I know the api call works because when I check the developer console in chrome, i can see the image in preview on the api call in the networks tab. I just cant seem to display it in vue.

It stores the image as blob?

enter image description here

I have added the responses as requested: enter image description here

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

The problem might be with Vue displaying Blob. Try:

xhr.onload = event => {
  this.image = URL.createObjectURL(xhr.response);
  event.preventDefault();
};

Here the URL.createObjectURL should create a reference to the Blob.

over 4 years ago · Santiago Trujillo Relatório

0

The problem lies not in the blob, but the vue tag to display the image. Instead of <image> we use <img> like this:

<img v-if="image !== null" :src="image" class="img-circle" alt="Services">
over 4 years ago · Santiago Trujillo 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