我第一次使用Firebase云功能存储。 我成功了 使用以下命令对默认文件夹执行更改:
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);
我该怎么做?
答案 0 :(得分:1)
当前无法为某些文件路径配置触发条件,类似于对数据库触发器的配置。
即您无法为'User_Pictures/{path}'
您需要做的是一旦触发该功能就检查the object attributes并在那里进行相应的处理。
针对每种情况要创建一个触发函数,如果不是您要查找的路径,则停止该函数。
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;
}
// ...
})
或者您执行主处理功能,将处理分派到不同的功能
functions.storage.object().onFinalize((object) => {
if (object.name.startsWith('User_Pictures/')) {
return handleUserPictures(object);
} else if (object.name.startsWith('MainCategoryPics/')) {
return handleMainCategoryPictures(object);
}
})