【问题标题】:Accessing older versions of a file with a Cloud function within Firebase在 Firebase 中使用 Cloud 函数访问文件的旧版本
【发布时间】:2020-04-18 00:17:39
【问题描述】:

enabled versioning 并在 Firebase 存储桶上使用 gsutil 访问了单个 json 文件的版本。我现在正在搜索如何使用云功能检索该文件的版本,并最终允许用户在需要时取回其工作的旧版本。我没有找到任何关于如何列出具有云功能的文件版本的文档。那可能吗?谢谢!

【问题讨论】:

  • 如果您将有关版本的信息存储在比 Cloud Storage 具有更灵活查询的数据库中,这可能会更容易。
  • 我认为你的评论是正确的道格。我现在正在学习 Firebase 存储。谢谢!

标签: firebase google-cloud-functions google-cloud-storage firebase-storage


【解决方案1】:

在 Cloud Functions 中,您将使用 access Cloud Storage through the Firebase Admin SDK for Node.js,它包含一个非常薄的包装器,围绕着常规的 Node.js SDK for Cloud Storage

看起来您可以将versions parameter 传递给getFiles method

应该是这样的:

const result = await bucket.getFiles({ versions: true })
result.files.forEach(file => {
  console.log(file.name);
});

【讨论】:

  • 然而,这将列出存储桶中的所有文件。我没有看到允许您列出单个文件版本的 API。唯一的示例显示 gsutil 和 REST API,它们也不是针对单个对象。您可能必须将其与选项中的前缀参数结合使用,以使其仅列出单个文件的版本。 cloud.google.com/storage/docs/using-object-versioning#list
  • 啊,在这种情况下,您可以使用前缀过滤器来过滤单个文件。只需传递prefix 选项的整个路径:bucket.getFiles({ prefix: 'path/to/file.jpg', versions: true })
猜你喜欢
  • 1970-01-01
  • 2018-03-29
  • 2017-11-03
  • 2021-08-11
  • 2021-04-17
  • 2020-01-12
  • 2020-05-02
  • 1970-01-01
  • 2018-09-02
相关资源
最近更新 更多