I’m working on a few Node.js projects where Amazon S3 buckets will be set up for each user who creates an account. I wanting to limit the total size of what a user can use.
I’ve been looking at the Knox client https://github.com/learnboost/knox which should make working with Amazon S3 easy when developing Node.js applications.
But after much research, I can’t seem to find a way of getting back a bucket file size efficiently – on which I can do user account limitations etc.
I’m hoping this is the right approach in the first, but maybe not? Conceptually, I’m wanting to store user account media files uploaded on Amazon S3 and I want to limit how much the user can upload and use in total.
Many thanks,
James
As Elf stated, there is no direct way to get the total size of a bucket from any of the S3 operations. The best you can do is loop through all of the items in the bucket and sum their respecive sizes.
Here’s a complete example of a program which lists all of the objects in a bucket and prints out a summary of file count and byte count at the end:
Feel free to copy it and change it to your requirements.