【问题标题】:(node:19820) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'byteLength' of undefined(节点:19820)UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“byteLength”
【发布时间】:2021-10-10 19:02:06
【问题描述】:

我正在尝试使用 express 创建一个 API,以将图像上传到 Firebase 存储。 出于某种原因,当我使用此端点时,它会抛出“(节点:19820)UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性'byteLength'”并且它没有响应。

router.post('/postImage', async (req, res) => {
    try {       
        storage.ref("images/" + uuid()).put({data: "hello"})
        .then(() => {
            return res.status(200)
        })
        .catch(() => {
            console.log("ERROR")
        })
    }
    catch(error) {
        console.log("LOL")
    }
})

【问题讨论】:

  • 您确定这是导致错误的代码吗?您正在掌握所有内容,除非您使用的库中存在问题,否则不应有未处理的承诺。

标签: javascript node.js firebase api express


【解决方案1】:

尝试记录错误,以查明发生错误的位置。

router.post('/postImage', async (req, res) => {
    try {
   const storageRef = storage.ref("images/" + uuid());       
   storageRef.put({ data : "hello" })
        .then(() => {
           res.status(200)
        })
        .catch((err) => {
            console.log("ERROR: " err);
        });
    }
    catch(error) {
        console.log("error: "error);
    }
})

【讨论】:

    猜你喜欢
    • 2020-08-18
    • 2020-12-11
    • 1970-01-01
    • 2019-12-15
    • 2021-08-31
    • 2021-09-01
    • 2021-07-05
    • 1970-01-01
    • 2020-12-27
    相关资源
    最近更新 更多