【问题标题】:Why is firebase cloud function invoked in react-native not logging output?为什么在 react-native 中调用 firebase 云功能而不是记录输出?
【发布时间】:2021-01-21 17:42:21
【问题描述】:

我有一个 Firebase 云功能:

exports.copyImage = functions.region('us-central1').https.onCall(async (data, context) => {
    const { auth } = context || {}
    const { uid } = auth || {}

    if (!uid) throw 'Unauthenticated'

    const srcBucketName = <bucket-name>'
    const destinationBucketName = '<bucket-name'
    const { imageFile, archiveId, sessionId } = data

    const srcFileName = `message-attachments/${imageFile}` 
    const destinationFileName = `archived-attachments/${uid}/${imageFile}`

    console.log(`source path: ${srcFileName}\ndestination path: ${destinationFileName}`)

    const storage = new Storage()
    storage
        .bucket(srcBucketName)
        .file(srcFileName) 
        .copy(storage.bucket(destinationBucketName).file(destinationFileName))
        .then(() => {
            console.log(`COPY SUCCESS: gs://${destinationBucketName}/${destinationFileName}`)
        })
        .catch(err => console.error('COPY ERROR: ' + err))
})

我有一个使用 react-native-firebase (v5) 调用此函数的 react-native 项目 (v61.5):

firebase.functions().httpsCallable('copyFile')({
  imageFile: fileName,
  archiveId: uid,
  sessionId
})
.then(() => {
 // copied file
 const ref = firebase.storage()
   .ref('archived-attachments')
   .child(uid)
   .child(fileName)
 ref.getDownloadURL()
   .then(url => {
     // do more
   })
   .catch(err => alert(err.message))
 })
 .catch(err => {
 // copy error
})

问题是执行此函数时,我没有在函数控制台中获得 any 日志输出。功能也已成功部署。有什么建议吗?

【问题讨论】:

  • 我注意到 http 函数名称 exports.copyImagefirebase.functions().httpsCallable('copyFile') 不匹配。你有什么错误吗?
  • 天哪。你是对的。哇。
  • @MuthuThavamani 你能在回答中发表你的评论来帮助别人吗
  • 是的,Jan. 也这样做了! :)

标签: firebase react-native google-cloud-functions react-native-firebase


【解决方案1】:

在此答案中更新我的评论,因为它解决了问题。

出现问题是因为 Jim 触发了另一个函数 copyFile 而不是copyImage

函数名称 exports.copyImagehttpsCallable('copyFile') 不匹配。

更新函数名解决了问题!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-19
    • 1970-01-01
    • 2021-04-08
    • 2021-09-18
    相关资源
    最近更新 更多