Firebase 函数 SDK 1.0.0 storage.onFinalize() 未按预期工作 [英] Firebase functions SDK 1.0.0 storage.onFinalize() not working as expected

查看:16
本文介绍了Firebase 函数 SDK 1.0.0 storage.onFinalize() 未按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Firebase 函数检测到 Storage 的上传事件,并将下载 URL 写入数据库,如下所示:

I use Firebase function to detect an upload event to Storage and write the download URL to the database like so:

exports.processFile = functions.storage.object().onChange((event) => {
  const object = event.data,
        filePath = object.name;

  if (object.resourceState === 'exists') {
    // Do something
  }
}

收到一封关于 SDK 1.0 的电子邮件我更新了这样的功能:

Getting an email about the SDK 1.0 I updated the function like this:

exports.processFile = functions.storage.object().onFinalize((object, context) => {
  const filePath = object.name;

  if (object.resourceState === 'exists') {
    // Do something
  }
}

更新后,函数坏了,所以我决定在日志中打印resourceState,得到一个undefined.这是怎么回事?

After the update, the function broke so I decided to print the resourceState in the log and got an undefined. What is going on?

推荐答案

在 SDK 1.0 之前只有 onChange() 事件.它触发了对存储对象的所有更改,并且必须测试 resourceState 在对象元数据中确定更改是创建、更新还是删除.

Before SDK 1.0 there was only the onChange() event. It fired for all changes to the storage object and one had to test resourceState in the object metadata to determine if the change was a creation, update, or deletion.

在 SDK 1.0 中,onChange() 一直是 替换为四个事件,省去测试resourceState的值:

In SDK 1.0, onChange() has been replaced by four events, eliminating the need to test the value of resourceState:

  • onArchive()
  • onDelete()
  • onFinalize()
  • onMetadataUpdate()

虽然 ObjectMetadata 的文档仍然显示 resourceState,我的猜测是它已从 SDK 1.0 中删除,因为不再需要它.

Although the documentation for ObjectMetadata still shows resourceState, my guess is that it has been removed from SDK 1.0 because it is no longer needed.

这篇关于Firebase 函数 SDK 1.0.0 storage.onFinalize() 未按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆