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

前端 未结 4 914
失恋的感觉
失恋的感觉 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:33

    You may check inside the function. Get the "filePath" or "fileDir" on your function and check if it is the folder you want.

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

提交回复
热议问题