【问题标题】:404 error to show image from firebase storage显示来自 Firebase 存储的图像时出现 404 错误
【发布时间】:2017-07-07 07:01:21
【问题描述】:

我想显示上传的图片,但即使我登录也收到 403 错误。 上传效果很好,downloadURl 没问题。 而且我已经通过了身份验证(上传成功表明我已经登录了) 但我无法显示上传的图片。

storage.child(file_name).put(event_image).then(function(snapshot) {
        console.log('Uploaded a blob or file!');
        var img_src = snapshot.downloadURL;
        $('img#uploaded').attr('src',img_src);
});

【问题讨论】:

    标签: image firebase http-status-code-403 firebase-storage


    【解决方案1】:

    使用此链接:https://firebase.google.com/docs/storage/web/download-files#download_data_via_url

    storageRef.child('images/stars.jpg').getDownloadURL().then(function(url)     {
        // `url` is the download URL for 'images/stars.jpg'
    
       // This can be downloaded directly:
       var xhr = new XMLHttpRequest();
        xhr.responseType = 'blob';
        xhr.onload = function(event) {
        var blob = xhr.response;
        };
        xhr.open('GET', url);
        xhr.send();
    
         // Or inserted into an <img> element:
          var img = document.getElementById('myimg');
           img.src = url;
         }).catch(function(error) {
         // Handle any errors
    });
    

    【讨论】:

      猜你喜欢
      • 2016-09-28
      • 1970-01-01
      • 2022-01-19
      • 2018-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-21
      • 1970-01-01
      相关资源
      最近更新 更多