I'm implementing a functionality in our app where users buy a subscription and create their workspace. Each subscription plan has different storage limits (e.g, 5 GB for a small plan). We use Backblaze B2 for storage, and currently, we create a separate bucket whenever an organization is created, which works fine.
However, I need to limit the bucket upload size according to the subscription plan the user has purchased. I have researched a lot but couldnt find a way to enforce storage limits on Backblaze buckets. Moreover, Backblaze doesn't seem to offer a way to get the storage size of a bucket or a whole folder.
I have gone through Backblaze documentation and searched online for any existing solutions or workarounds but haven't found a way to directly limit the storage size of a bucket. I expected to find a method or API that allows setting storage quotas or retrieving the total size of a bucket to enforce these limits programmatically.
Additionally, I'm using @aws-sdk/client-s3
for managing S3-compatible storage.
Does anyone know how to implement storage limits on Backblaze B2 buckets based on the user's subscription plan? Any advice or workarounds would be greatly appreciated. Thanks!
Enforcing storage limits on Backblaze B2 buckets isn't supported directly. You'll need to track storage usage separately in your application by yourself but here is how I can help you:
Track Usage: Maintain a record of storage usage for each user's workspace in your application's database.
Enforce Limits: Before allowing any storage operations (like uploads), check against the recorded usage to ensure it doesn't exceed the subscribed limit.
Notifications: Provide feedback to users when they near or exceed their storage limits, using messages or notifications in your app.
Periodic Checks: Implement checks to reconcile and clean up storage usage periodically.
If you have any specific questions or need more details on implementing this, let me know!