Firebase函数SDK 1.0.0 storage.onFinalize()无法正常工作 [英] Firebase functions SDK 1.0.0 storage.onFinalize() not working as expected

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

问题描述

我使用Firebase函数检测到存储的上传事件,并将下载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之前,只有对象元数据中的> 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天全站免登陆