最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - error 400 when accessing firebase storage trying to get file url - Stack Overflow

programmeradmin7浏览0评论

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

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 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;
            }
        });

    }
}

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

any help with this issue?

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

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 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;
            }
        });

    }
}

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

any help with this issue?

Share Improve this question edited Feb 13, 2017 at 14:39 Frank van Puffelen 599k85 gold badges889 silver badges859 bronze badges asked Feb 13, 2017 at 10:57 Ron BittermanRon Bitterman 1311 silver badge6 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 15

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

If you want to access: https://firebasestorage.googleapis./v0/b/BUCKET.appspot./o/images/folder/image.png?alt=media

Then write this: https://firebasestorage.googleapis./v0/b/BUCKET.appspot./o/images%2Ffolder%2Fimage.png?alt=media

Try to use the the full image path like the below

// 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;
                }
            });

        }
    }
发布评论

评论列表(0)

  1. 暂无评论