Add rule to limit maximum folder size for cloud storage in firebase

How can I add a rule to limit the maximum amount of storage space that a user can consume? Current request.resource.size

limits the size of the file that the user can upload, but not the size of the folder / bucket that the user uploads to. I want to set a 50MB limit over all content the user can download.

Update:

To revisit the question, imagine that a user has already uploaded 5 10MB images, each of which is 50MB. Now I want to restrict the user to upload any files as the maximum bucket size (in my case: 50MB) has already been reached. There may have been 2 files of 20 MB each and one of 10 MB, but the total size of 50 MB should be respected. How do I add a rule for this?

Update 2:

Is it that, in the current implementation, an authenticated user can continue to download an infinite amount of data, say with a file size of 10MB each, at the expense of the user serving the Firebase service (assuming the payment is at your cost during hosting)?

+3


source to share


2 answers


The current Firebase design does not allow you to create rules to limit the size of the bucket.

The best version would be keeping track of the bucket size on your own server as well as passing all uploads with Firebase through your custom server. Basically, the file is uploaded to your server, checked for bucket size, and then uploaded again to AWS S3 or Google storage.



After that, you can remove the download from the server by updating the metadata in your database.

+1


source


You can directly do this on the client side by checking the file size. Check out the File api which has a method size method. You can check if the user has exceeded the file limit, and then you can restrict it to upload.



0


source







All Articles