Reputation: 4987
I need to alow user to store 50Mb of files in cloud storage and monthly data transfer up to 5Gb for the files added by the user
For example consider this is a blog app and any body can create blog and post text, image or videos
Public can view that blog and that file usage will goto the blog created user account
Is there any way (api) to get this data usage in this case from firebase cloud storage
Example
User bob created a blog and it contain a large text and two images and the size of the images is 200kb and if 100 user read this blog then the user bob account need to show that the total storage usage is 200kb and data transfer is 200kb100 and remaining is 5Gb- 200kb100+200kb
We can't store the file size in firestore when ever user start using the app bez it will be expensive
The user can view the blog without signup and we are not able to calculate the image size and update in db
In app we only get the app URL and if we create a variable file usage and if we keep updating it then firestore will produce a big amount invoice so we need to avoid that. if 10 user make 10 blog and if each blog contains 10-15 images and if 100 user read that blog then the update operation will will a large number and the invoice will be larger than we expected and it will be more that our budget
Upvotes: 1
Views: 432
Reputation: 1494
Currently there's no way to get the network transfer per user from firebase, the closest you can get is to monitor the total usage from the Firebase Console.
Regarding the size of the file stored, once the user has uploaded it, you can get the information from the storaged file metadata for Android, for Web and for IOS, you can sum up all the different file sizes and save only the total amount per user.
Upvotes: 0
Reputation: 741
I suggest when you create the post, also save the uid of the user's document in Firestore and the post's size (I'm sure there is a way to calculate it client-side, depend on which platform you are developing on). And then when another user read the post, just do a simple write to update a properties in the author's document (because you already have the uid), let's say dataCap
, increase it by 200000
for a 200kb post. This way you will have to make 1 extra document write per blog view. Considering the pricing of Firestore at 0.18$ per 100k document writes (that's the price at my region, yours may vary), you'll need millions view to start paying more than a few dollars.
Upvotes: 2