首页 > 解决方案 > 如何从 Firebase 存储访问图像?

问题描述

我想访问已上传到 Firebase 存储的图像。我已经尝试过他们在https://firebase.google.com/docs/storage/web/download-files中告诉我的内容,但它不起作用。

我想做的很简单。我有一个带有来源的“img”标签。使用 Vue.js,我想将上传的文件路径分配给图像源。

这就是我现在所拥有的:

loadImage(details) {
  console.log(details.email);
  var storage = firebaseApp.storage();
  var gsReference = storage.refFromURL('gs://icachatdam.appspot.com/profilePics/jordi@test.com/profPic.png')
  this.picture = gsReference.fullPath;
}

其中变量“图片”是图像源:

<q-img :src="this.picture" spinner-color="white" style="height: 140px; max-width: 150px" />

标签: firebasevue.jsquasar-framework

解决方案


感谢道格的回复,我已经测试了更多,这终于对我有用:

loadImage(details) {
  var starsRef = firebaseApp.storage().ref().child('profilePics/'+details.email+'/profPic.png');

  starsRef
    .getDownloadURL()
    .then(url => {
      this.pictureURL = url;
      //console.log(this.pictureURL);
    });
}

推荐阅读