【问题标题】:How to link user information of firebase_auth with files uploaded to other databases如何将firebase_auth的用户信息与上传到其他数据库的文件链接起来
【发布时间】:2020-07-03 01:21:17
【问题描述】:

我正在尝试使用 Flutter 和 Firebase 制作类似图像/视频共享应用程序。

使用 firebase_auth 进行用户注册和身份验证 使用 firebase_storage 上传文件 将数据保存在 cloud_firestore 等中←现在在这里

我正在查看,但我正在与他们合作,例如,

链接用户信息(用户id)和上传的文件, 我想知道谁上传了每个文件, 我该怎么办?

如果我能做到, 我可以按用户 ID 搜索文件, 我根据文件上传的数量给每个用户打分 我认为你可以这样做。

我需要使用 Firestore 或其他东西吗?

【问题讨论】:

    标签: firebase flutter firebase-authentication


    【解决方案1】:

    我相信一个好的方法是在 Firestore 数据库中为 videosimages 创建一个集合,甚至是一个名为 media 的通用集合,其中每个文档都有关于上传媒体的信息,例如类型(视频/图像)、来自 Firebase 存储的文件 url、用户 ID 和上传日期。您可以创建这样的模型,例如:

    class UserMedia {
      String userId;
      String mediaUrl;
      String mediaType; // media type can be video, image, audio, etc.
      DateTime uploadedAt;
    }
    

    然后在您的 Firestore 数据库中,您可以创建如下结构:

    /media/{userId}/{userMedia} //here userMedia is a document created with the model described above.
    

    对 Firebase 存储也是如此。如果文件不存在,您可以将文件保存在 Storage 基于路径创建的文件夹中。 例如,您可以上传一个传递一些变量(例如 userId)的文件,存储将创建文件夹,例如:

    /media/{userId}/image_{userId}_{imageId}.jpg
    

    【讨论】:

    • 感谢您的回答。我认为可以通过您向我们展示的方法来实现。我会做一些研究,以便具体实施。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-15
    • 1970-01-01
    • 2010-10-01
    • 2013-12-03
    • 1970-01-01
    • 2021-06-10
    相关资源
    最近更新 更多