2017-02-13 38 views
1

我正在尝试离子和firebase平台,我遇到了问题。错误400访问firebase存储试图获取文件url

所以我有存储中的图像我试图访问,我试图使用getDownloadURL()方法,但我不断收到错误400,“无效http方法/ url对”。我无法找到任何解决方案。尝试使用getMetadata()时出现同样的错误。

firebase已初始化,现在所有的工作都很好,认证,数据库读取等等。除了这个错误...

我有下面的代码在服务..

// Get a reference to the storage service, which is used to create references in your storage bucket 
var storage = firebase.storage(); 

// Create a storage reference from our storage service 
var storageRef = storage.ref(); 

// Create a child reference 
var imagesRef = storageRef.child('images'); 
// imagesRef now points to 'images' 

return { 
    getImgRef: function (imgName) { 
     var imgRef = imagesRef.child('Tanker.ico') 
     imgRef.getDownloadURL().then(function (url) { 
      return url 
     }).catch(function(error) { 
      switch (error.code) { 
       case 'storage/object_not_found': 
        // File doesn't exist 
        break; 

       case 'storage/unauthorized': 
        // User doesn't have permission to access the object 
        break; 

       case 'storage/canceled': 
        // User canceled the upload 
        break; 

       case 'storage/unknown': 
       // Unknown error occurred, inspect the server response 
        break; 
      } 
     }); 

    } 
} 

一切顺利,直到getDownloadURL(),如果同一我尝试的getMetaData()。

这个问题的任何帮助?

回答

1

尝试使用类似的完整图像路径下

// Get a reference to the storage service, which is used to create references in your storage bucket 
    var storage = firebase.storage(); 

    // Create a storage reference from our storage service 
    var storageRef = storage.ref(); 

    // Create a child reference 
    var imagesRef = storageRef.child('images/Tanker.ico'); 
    // imagesRef now points to 'images' 

    return { 
     getImgRef: function (imgName) { 
      //var imgRef = imagesRef.child('Tanker.ico') 
      imagesRef.getDownloadURL().then(function (url) { 
       return url 
      }).catch(function(error) { 
       switch (error.code) { 
        case 'storage/object_not_found': 
         // File doesn't exist 
         break; 

        case 'storage/unauthorized': 
         // User doesn't have permission to access the object 
         break; 

        case 'storage/canceled': 
         // User canceled the upload 
         break; 

        case 'storage/unknown': 
        // Unknown error occurred, inspect the server response 
         break; 
       } 
      }); 

     } 
    } 
相关问题