[英]How can I access a specific folder inside firebase storage from a cloud function?
I am using firebase cloud function storage for the first time.我是第一次使用 firebase 云函数存储。 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但现在我希望从存储文件夹内的文件夹中触发该功能,如下所示
How can I do that?我怎样才能做到这一点?
There is currently no way to configure trigger conditions for certain file paths, similar to what you can do with database triggers.当前无法为某些文件路径配置触发条件,类似于您可以使用数据库触发器执行的操作。
ie you can not set a cloud storage trigger for 'User_Pictures/{path}'
即您不能为
'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);
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.