Limit number of files in a firebase storage path

前端 未结 1 1630
暗喜
暗喜 2021-01-14 09:07

I want to limit the number of files that a user can upload to a firebase storage path. Here is my firebase storage rule:

   service firebase.storage {
  matc         


        
1条回答
  •  北海茫月
    2021-01-14 09:21

    In case any one needs an answer I found the solution by using firebase cloud functions:

    exports.getNumOfFile = functions.storage.object().onChange(event => {
        const object = event.data; // The Storage object.
        const fileBucket = object.bucket; // The Storage bucket that contains the file.
        const bucket = gcs.bucket(fileBucket);
        bucket.getFiles({
            prefix: "[path]", //Path like what you use to get reference of your files in storage 
        }, (error, files) => {
            console.log(files.length);
        });
    });
    

    You can find more options here:

    https://googlecloudplatform.github.io/google-cloud-node/#/docs/storage/1.1.0/storage/bucket?method=getFiles

    0 讨论(0)
提交回复
热议问题