The*_*Ben 10 google-cloud-storage firebase google-cloud-functions firebase-storage
我已成功测试Firebase功能以进行存储.但是,我没有看到任何提示如何仅在将文件添加到我的存储桶中的文件夹时调用该函数.我已经看到了关于划定范围的功能,唯一的暗示是不同的桶在这里.
是否可以将功能范围扩展到我的存储桶中的文件夹,如果是,如何?或者我需要多个存储桶而不是文件夹来分隔不同的任务.
Fra*_*len 12
这里有一个firebaser
目前无法仅针对云存储中特定文件夹中的写入触发云功能.如果要将触发限制为项目中文件的子集,则将它们放在单独的存储桶中是目前实现这一目标的唯一方法.
您可以检查函数内部。在您的函数上获取“filePath”或“fileDir”并检查它是否是您想要的文件夹。
const path = require('path');
const filePath = event.data.name;
const fileDir = path.dirname(filePath);
//if you want to check the posts folder only then:
if (fileDir != 'posts') {
console.log('This is not in post folder');
return null;
}
Run Code Online (Sandbox Code Playgroud)
请注意,Google Cloud Storage 在平面文件系统上运行。所以实际上没有目录。如果您存储的文件基本上/users/profile_pictures/photo.jpg
是文件名的所有部分。所以实际上,没有目录。只有文件。这就是目录本身不能有触发器的原因。当然,您可以通过检查文件本身的名称并查看其开头是否与特定字符串匹配来解决此问题。
export const generateThumbnailTrigger = functions.storage.object().onFinalize(async (object) => {
const filePath = object.name;
if (filePath?.startsWith('temp/')) {
console.log('start doing something with the file');
} else {
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1923 次 |
最近记录: |