firebase - 为什么在 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
})
问题是执行此功能时,我没有在功能控制台中获得任何日志输出。功能也已成功部署。有什么建议吗?
解决方案
更新我在这个答案中的评论,因为它解决了这个问题。
出现此问题是因为 Jim 一直在触发不同的功能copyFile
,而不是copyImage
.
函数名
exports.copyImage
与httpsCallable('copyFile')
.
更新函数名解决了这个问题!
推荐阅读
- c++ - 如何在多个函数中操作 ifstream 对象
- unix - grep 和 awk,组合命令?
- ruby-on-rails - Sidekiq 工人重复工作的最佳实践
- git - git remote set-url 和 remote remove 之间的区别然后添加?
- java - 按字母顺序打印列表中每个单词的计数
- cesium - 铯中的这种暗图像是否正常?
- tableau-api - 我可以在一个计算字段中进行多项计算吗?
- r - How to use Rvest to scrape data
- java - Java tomcat线程内存使用限制
- android - React Native 不使用 Android Studio 链接模块