I've seen previous questions on "How to find the size of an entire S3 bucket." This is somewhat of a different question-- so I apologize in advance if it is vague. I'll do my best to explain what I am trying to achieve.
I am currently using Amazon S3 PHP Class.
This is what I am trying to achieve:
I would like to be able to loop through my MySQL database and get specific filenames of files on my S3 server. (This may be based on user).
During the loop, query the Amazon S3 bucket (somehow) and get the filesize of each file that was in my MySQL loop.
Add up all the filesizes, to get one total approximate bytesize.
So, essentially, let's say I have a user that has 5 files on the S3 bucket. How might I be able to query the S3 bucket, to see how much data this user's 5 files is storing in my bucket?
My apologies if this is difficult to understand. I can re-articulate, if needed.
Any nudge in the right direction would be greatly appreciated.
To find the size of a single S3 bucket, you can use the S3 console and select the bucket you wish to view. Under Metrics, there's a graph that shows the total number of bytes stored over time.
Individual Amazon S3 objects can range in size from a minimum of 0 bytes to a maximum of 5 TB. The largest object that can be uploaded in a single PUT is 5 GB.
Go to AWS Billing, then reports, then AWS Usage reports. Select Amazon Simple Storage Service, then Operation StandardStorage. Then you can download a CSV file that includes a UsageType of StorageObjectCount that lists the item count for each bucket.
You really should be storing the filesize in your Mysql table. Faster to get the info, less S3 cost.
But... try this?
$s3 = new Aws\S3\S3Client($parameters);
$obj_data = $s3->headObject([
'Bucket' => $bucket,
'Key' => $key
]);
echo 'Size is: '.$obj_data['ContentLength'];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With