尝试获取文件URL的Firebase存储访问时出现错误400

尝试获取文件URL的Firebase存储访问时出现错误400

本文介绍了尝试获取文件URL的Firebase存储访问时出现错误400的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用离子平台和Firebase平台,但遇到了问题.

I'm trying the ionic and firebase platforms and i ran into a problem.

所以我在尝试访问的存储中有一个图像,我尝试使用getDownloadURL()方法,但始终收到错误400,无效的http方法/URL对".我找不到任何解决方案.尝试使用getMetadata()时出现相同的错误.

so i have an image in the storage I'm trying to access, i tried using the getDownloadURL() method but i keep getting an error 400, "invalid http method/url pair". i can't find any solution to it. same error when trying to use getMetadata().

firebase已初始化,并且现在一切正常,身份验证,数据库读取等等.除了这个错误...

firebase is initialized and all is working well for now, authentication, database readings and all. except for this error...

我在服务中包含以下代码.

i have the following code in a service..

// 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()也是一样.

all goes well until the getDownloadURL(), same if i try getMetadata().

此问题有帮助吗?

推荐答案

在存储桶后有正斜杠(/)的地方使用%2F,例如:

Use %2F where there is forward slash (/) after bucket, like:

如果要访问: https://firebasestorage.googleapis.com/v0/b/BUCKET.appspot.com/o/images/folder/image.png?alt = media

然后写这个: https://firebasestorage.googleapis.com/v0/b/BUCKET.appspot.com/o/images%2Ffolder%2Fimage.png?alt = media

这篇关于尝试获取文件URL的Firebase存储访问时出现错误400的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 11:07