Start a new topic

How to limit a user account in code to 2GB?

Hi kindly post or reference a link where we can see code to limit user account to fix amount of data storage.

We need to set that user are limited to 2Gb of storage.

Hello Medpike,

There is currently no way to automatically implement a limit on storage for a single user baked into Kinvey, though it is an interesting idea.  There may be ways to go about doing this that I'm not thinking of at this time.


Damien can we read how much storage has a user?



We don't calculate storage per user, we calculate how much each back-end is using and limit our users based on that.  There wouldn't be a way for us to offer you this capability directly.


While it's true that we don't offer statistics or an out-of-the-box way to see or restrict total file usage per user, you could achieve this using some clever business logic code.

When uploading a file, the client libraries create a record of its metadata on Kinvey, which includes the byte size of the uploaded file in the size property ( You could create post-save business logic on the files collection which finds the ID of the user making the request (available through, and then updates this user entity (using $inc syntax in combination with the update command -- with a running total of the size of files uploaded by the user. Then, in a pre-save hook on the files collection, you could fetch the record of the current user, check whether the total amount uploaded by the user is more than the limit you want to enforce, and reject the request if needed.

Please note that this is a fairly specific use case, and as such we don't have a code sample for it; since we are a self-service platform, you will need to figure out how to go from the above description to working code. Hope this helps!
Login or Signup to post a comment