我正在尝试离子和火力平台,我遇到了一个问题。
所以我在我试图访问的存储中有一个图像,我尝试使用getDownloadURL()方法,但我一直收到错误400,“无效的http方法/网址对”。我找不到任何解决方案。尝试使用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(),也一样。
有关此问题的任何帮助吗?
答案 0 :(得分:4)
使用%2F,其中包含正斜杠(/),例如:
如果您想访问: https://firebasestorage.googleapis.com/v0/b/BUCKET.appspot.com/o/images/folder/image.png?alt=media
答案 1 :(得分:2)
尝试使用如下所示的完整图像路径
// 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;
}
});
}
}