eleven0's avatar

Advice on How to Get s3 Directory or Upload Sizes for Uploads

Hello All,

I use s3 for my storage needs of my app, I want to control amount of space that customer has with my application. Price of their subscriptions will depend on that.

Should I store the size information of each singular upload and or is there an easier way to see how much of a space a specific customer uses for a specific project? My file structure is that I have one folder for each customer, but that folder can have many projects, other uploads from that customer. Also their project folder can have different sub-directories. Close to a dozen models for uploads....

What do you think?

0 likes
1 reply
Cronix's avatar

I would store the size of the individual uploads as bytes (not kb or mb...just bytes) for each upload in the db. I assume you're already storing the filename, etc. That would allow you to do real time calculations locally. You could just create a totalSize method or something that would return the size of all files for that user added together.

Laravel's fly system will let you get the size of individual files, but not the entire directory (without looping, etc), so that's why I suggest the above.

Please or to participate in this conversation.