为什么在 react-native 中调用 firebase 云函数而不记录输出?
Why is firebase cloud function invoked in react-native not logging output?
我有一个 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 日志输出。这些功能也已成功部署。有什么建议吗?
更新我在这个答案中的评论,因为它解决了这个问题。
出现此问题是因为 Jim 一直在触发不同的功能 copyFile
而不是 copyImage
.
mismatch between the function name exports.copyImage
vs httpsCallable('copyFile')
.
更新函数名称解决了问题!
我有一个 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 日志输出。这些功能也已成功部署。有什么建议吗?
更新我在这个答案中的评论,因为它解决了这个问题。
出现此问题是因为 Jim 一直在触发不同的功能 copyFile
而不是 copyImage
.
mismatch between the function name
exports.copyImage
vshttpsCallable('copyFile')
.
更新函数名称解决了问题!