如何通过云功能访问Firebase存储内的特定文件夹? [英] How can I access a specific folder inside firebase storage from a cloud function?

查看:32
本文介绍了如何通过云功能访问Firebase存储内的特定文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次使用Firebase云功能存储.我成功了使用以下命令在默认文件夹上执行更改:

I am using firebase cloud function storage for the first time. I succeeded to perform changes on the default folder by using :

exports.onFileUpload = functions.storage.bucket().object().onFinalize(data => {
const bucket = data.bucket;
const filePath = data.name;
const destBucket = admin.storage().bucket(bucket);
const file = destBucket.file(filePath);

但是现在我希望从存储中的文件夹中触发该功能像这样的文件夹

but now I want the function to be triggered from a folder inside the storage folder like this

我该怎么做?

推荐答案

当前无法为某些文件路径配置触发条件,类似于对数据库触发器的配置.

There is currently no way to configure trigger conditions for certain file paths, similar to what you can do with database triggers.

即您无法'User_Pictures/{path}'

您要做的是检查对象属性触发该功能并在那里进行相应处理.

What you have to do is to inspect the object attributes once the function is triggered and handle it accordingly there.

针对每种情况要创建一个触发函数,如果不是要查找的路径,则停止该函数.

Either you create a trigger function for each case you want to handle and stop the function if it's not the path you're looking for.

functions.storage.object().onFinalize((object) => {
  if (!object.name.startsWith('User_Pictures/')) {
    console.log(`File ${object.name} is not a user picture. Ignoring it.`);
    return null;
  }

  // ...
})

或者您可以执行主处理功能,将处理分派到不同的功能

Or you do a master handling function that dispatches the processing to different functions

functions.storage.object().onFinalize((object) => {
  if (object.name.startsWith('User_Pictures/')) {    
    return handleUserPictures(object);
  } else if (object.name.startsWith('MainCategoryPics/')) {
    return handleMainCategoryPictures(object);
  }
})

这篇关于如何通过云功能访问Firebase存储内的特定文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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