Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃殌 Feature: Retrieve and limit total storage used #5955

Open
2 tasks done
XaFigg opened this issue Aug 8, 2023 · 8 comments
Open
2 tasks done

馃殌 Feature: Retrieve and limit total storage used #5955

XaFigg opened this issue Aug 8, 2023 · 8 comments
Labels
product / storage Fixes and upgrades for the Appwrite Storage.

Comments

@XaFigg
Copy link

XaFigg commented Aug 8, 2023

馃敄 Feature description

Hello, I would like to propose a new feature 馃槃

The idea would be to be able to retrieve or limit the total storage used by a user, a team or simply the total storage that a bucket uses.

An example, for the user to retrieve their total storage usage:

// Optional parameter, if no parameter, function returns storage usage of 
// all buckets (only files owned by user).
storage.getStorageUsed("[BUCKET_ID]")

Another example to retrieve the total storage usage of a bucket:

// Server side SDK.
storage.getStorageUsed("[BUCKET_ID]")

The administrator can limit from the appwrite interface, the use of total storage for each user/team/bucket.

馃帳 Pitch

For example, for a data hosting service, it would be important to be able to monitor the storage usage of each user/team/bucket and to be able to limit in order to avoid abuse.

馃憖 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

馃彚 Have you read the Code of Conduct?

@gewenyu99
Copy link

@XaFigg If we just included a way to track total storage per bucket, and you used one bucket per person, would this partially solve your issues?

I think this would be easiest, but I am also supportive of a proper, permission conscious way to count total storage used.

Alternatively, Appwrite Functions triggered by storage events would work, too. Have a collection be auto updated by functions that tracks each user's files.

If you see that there's significant friction in both these paths, we can decide how to fix the problem.

Sometimes the solution is to add a more flexible way to write functions or queries in Storage to allow user implementation.

Anyway, happy to hear further feedback from you an community. I'll keep a close eye on this issue!

@XaFigg
Copy link
Author

XaFigg commented Aug 9, 2023

Hello @gewenyu99,
This is indeed a possibility, so you'd have to create a bucket when you create a user. I imagine this could be done automatically with Functions.

What I'm looking for is a way to limit storage usage per user. It could be done via the first solution mentioned, by checking bucket usage.

But I think that putting functions in the storage will allow the user to do as he likes.

I'm using a translator, sorry if I'm not explicit enough.

@gewenyu99
Copy link

Hello @gewenyu99, This is indeed a possibility, so you'd have to create a bucket when you create a user. I imagine this could be done automatically with Functions.

What I'm looking for is a way to limit storage usage per user. It could be done via the first solution mentioned, by checking bucket usage.

But I think that putting functions in the storage will allow the user to do as he likes.

I'm using a translator, sorry if I'm not explicit enough.

No problem. I feel like this should be done with functions one way or another. If we find out we can't it might be more of a problem with the way our function/events work.

If you think about it:

  1. User uploads/delete file
  2. Function triggered
  3. File metadata, including size and uploader is saved to a collection somewhere.
  4. When you need to see how much data a user has used, query all files by the user from the collection and find total size used. (even if you have a few thousand files, this should still be a pretty quick query, since it's a indexed match for userID)

I think if we build this into the bucket directly, it'll be less flexible than improving powerful features like functions to help you build custom logic.

Again, if this doesn't work, let us know, we'll find another solution together.

Cheers!

@XaFigg
Copy link
Author

XaFigg commented Aug 10, 2023

Hello 馃槃

I think I'll do it this way, it seems like a good solution. On the other hand, I don't yet know how I can limit the total size, for example if the user uploads a file, he'll get an error saying he's already reached the storage limit.

Thanks for your feedback ^^

@safwanyp
Copy link
Contributor

On the other hand, I don't yet know how I can limit the total size, for example if the user uploads a file, he'll get an error saying he's already reached the storage limit.

You could have a function do this for you, like so:

  • Pass the userId to the function
  • Query the collection that was suggested before by Wen
  • Calculate the total and return it
  • If returned total > specified total, show error message (could be done in the function instead of the client-side app as well)

@XaFigg
Copy link
Author

XaFigg commented Aug 14, 2023

Hello,
Thank you for your return safwanyp, I keep it aside for when I need it.
For now, I was able to deploy a function that creates a bucket when a user registers.
The problem is that I'm using OAuth authentication, and from what I've seen the user creation event does not fire with this type of authentication :/

@safwanyp
Copy link
Contributor

Hello, Thank you for your return safwanyp, I keep it aside for when I need it. For now, I was able to deploy a function that creates a bucket when a user registers. The problem is that I'm using OAuth authentication, and from what I've seen the user creation event does not fire with this type of authentication :/

That is true. There is an open issue about this: #2406

For now, you can manually execute the function from your client-side with the createExecution endpoint.

@gewenyu99
Copy link

Yeah @stnguyen90 is working to fix that issue, I believe. 馃槄 Sorry about that. I know it's frustrating, we're trying to get it fixed.

CC: @XaFigg

@stnguyen90 stnguyen90 added the product / storage Fixes and upgrades for the Appwrite Storage. label Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product / storage Fixes and upgrades for the Appwrite Storage.
Projects
None yet
Development

No branches or pull requests

4 participants