Is it possible to scope Firebase functions to a folder inside a storage bucket?

前端 未结 4 918
失恋的感觉
失恋的感觉 2020-12-07 00:59

I have tested Firebase functions for storage successfully. However, I havn\'t seen anywhere a hint how to only invoke the function when a file is added into a folder inside

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-07 01:14

    Please note that Google Cloud Storage works on a flat filesystem. So practically there are no directories. If you're storing a file like /users/profile_pictures/photo.jpg it is basically all part of the file name. So in reality, there are no directories. There are just files. Which is why there cannot be a trigger on a directory per se. Of course you can work that around by checking the name of the file itself and see whether its start matches a particular string or not.

    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;
        }
    });
    

提交回复
热议问题