Firebase 存储:尽管处理了它,但仍然收到 404 错误

时间:2021-01-13 12:35:01

标签: javascript firebase error-handling http-status-code-404 firebase-storage

  • 在 HR 网络应用程序中,我有一个呈现给 DOM。
  • 每个人在 Firebase Storage 中都有或没有简历。因此,我需要确定应该显示哪个按钮:“下载简历”或“上传简历”。
  • 为了检查这一点,我在文件引用上调用 .getDowloadURL()。
  • 如果找到简历,会显示“下载简历”按钮,一切正常
  • 如果没有找到,则返回错误
  • 然后我捕获此错误并处理它以在 DOM 上显示“上传简历”按钮

我的问题是,对于每个没有简历的候选人,我仍然在控制台中收到 404 错误。 (我也尝试过 onResolve、onReject,但问题是一样的)。

非常感谢您的任何提示!

这是我的代码:

    firebase.storage().ref().child('cvs').child(doc.id).child('CV').getDownloadURL()
        .then(function (url) {
            
            document.getElementById('dwlCvBtn' + doc.id).classList.remove('d-none')


        }).catch(function (error) {


            // A full list of error codes is available at
            // https://firebase.google.com/docs/storage/web/handle-errors
            switch (error.code) {
                case 'storage/object-not-found':
                    document.getElementById('uploadCvBtn' + doc.id).classList.remove('d-none')
                    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 个答案:

没有答案