firebase - 从firebase云函数获取UID

标签 firebase firebase-storage google-cloud-functions

当我触发存储事件时,有没有办法获取uid

我想在图像上传到 Firebase 存储时创建一个拇指,然后更新数据库中用户图像配置文件的 URL...

exports.uploadphoto = functions.storage.object().onChange(event => {
  // ...
});

最佳答案

两个选项

您可以将图像存储到包含 uId 的路径 然后使用event.data.name获取文件路径

或者

上传时将其添加到自定义元数据中,然后通过以下方式在云函数中访问:

const metadata = event.data.metadata
const uId = metadata.uId  

uId 可以是您上传时所称的任何名称。

使用自定义元数据文档上传

iOS:https://firebase.google.com/docs/storage/ios/file-metadata

安卓:https://firebase.google.com/docs/storage/android/file-metadata

网址:https://firebase.google.com/docs/storage/web/file-metadata

关于firebase - 从firebase云函数获取UID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45964226/

相关文章:

android - 我是否需要扩展 FirebaseInstanceIdService 才能订阅 FCM 主题?

android - 错误 : cannot access zzbgl

firebase - 我可以在 Firebase/Google Cloud Storage 存储桶上设置文件夹或存储桶级别 "cacheControl"设置吗?

node.js - Cloud Functions 何时重试?

firebase - 云函数错误 : cannot convert an array value in an array value

firebase - 如何使用 Google Apps 脚本使用 Firebase Auth REST API?

java - 如何让我的回收器适配器检索发送到 firebase 数据库的消息?

ios - 同步下载 Firebase 存储

android - 如何解决 java.lang.IllegalStateException : Task is not yet complete Error when uploading image to Firebase storage?

node.js - Node/Firebase onCall 异步函数返回