试图通过获取获取图像,图像存储在firebase存储中

问题描述 投票:0回答:1

嗨,我正在尝试使用提取API获取图像,该URL是有效的,因为当我将图像URL放入Img标记时,它可以正常工作。

我的提取功能:

   getImage = () => {  
   const url= "https://firebasestorage.googleapis.com/v0/b/alpha-c790f.appspot.com/o/images%2Frivers.jpg?alt=media&token=6a96d672-23c1-425f-bdca-47f6d73608f0"


fetch(this.state.url,{
  mode: 'no-cors'
}).then(response => response.blob())
.then((res)=>{
     console.log(res);
    var objectURL = URL.createObjectURL(res);
    var myImage = new Image();
    myImage.src = objectURL;

}).catch(err=>{
  console.log(err);
})
}

firebase云存储访问规则:

      rules_version = '2';
      service firebase.storage {
      match /b/{bucket}/o {
           match /{allPaths=**} {
           allow read, write: if request.auth != null;
           }
        }
    }

我想像这样实现它,因为我想在它上面放一个微调框,直到图像出现为止

我得到的答复是这个

           Blob {size: 0, type: ""}
                 size: 0
                 type: ""
            __proto__: Blob
reactjs firebase firebase-storage
1个回答
0
投票

您不需要获取图像,该图像已存在于此URL https://firebasestorage.googleapis.com/v0/b/alpha-c790f.appspot.com/o/images%2Frivers.jpg?alt=media&token=6a96d672-23c1-425f-bdca-47f6d73608f0

<img src='https://firebasestorage.googleapis.com/v0/b/alpha-c790f.appspot.com/o/images%2Frivers.jpg?alt=media&token=6a96d672-23c1-425f-bdca-47f6d73608f0'/>

如果您要按程序构造图像,也可以执行以下操作:

var newImgage = new Image() 
newImgage.src = 'https://firebasestorage.googleapis.com/v0/b/alpha-c790f.appspot.com/o/images%2Frivers.jpg'
© www.soinside.com 2019 - 2024. All rights reserved.