【发布时间】: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.copyImage和firebase.functions().httpsCallable('copyFile')不匹配。你有什么错误吗? -
天哪。你是对的。哇。
-
@MuthuThavamani 你能在回答中发表你的评论来帮助别人吗
-
是的,Jan. 也这样做了! :)
标签: firebase react-native google-cloud-functions react-native-firebase