首页 > 解决方案 > 为什么在 react-native 中调用 firebase 云功能而不是记录输出?

问题描述

我有一个 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
})

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

标签: firebasereact-nativegoogle-cloud-functionsreact-native-firebase

解决方案


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

出现此问题是因为 Jim 一直在触发不同的功能copyFile ,而不是copyImage.

函数名exports.copyImagehttpsCallable('copyFile').

更新函数名解决了这个问题!


推荐阅读