Is there any way i can get the size of a bucket from the google cloud in java.
I know you can get it like this:
gsutil du -s gs://[BUCKET_NAME]/
Is it possible to somehow obtain the total size of a bucket thorugh the java API?
Is there any way i can get the size of a bucket from the google cloud in java.
I know you can get it like this:
gsutil du -s gs://[BUCKET_NAME]/
Is it possible to somehow obtain the total size of a bucket thorugh the java API?
There is no function to get the size of a bucket with java API google-cloud-java.
You can iterate over blobs in the bucket and calculate the total size using blob.getSize()
but it would be very slow.
According to the official documentation, gsutil du
can take a long time for large buckets Getting bucket information:
Caution: The gsutil du command calculates space usage by making object listing requests, which can take a long time for large buckets. If the number of objects in your bucket is hundreds of thousands or more, use Stackdriver instead
An alternative solution would be to enable the bucket logging and check the size of the bucket from the logs:
Carefully calculating Google Cloud Storage Buckets size with Cloud Functions & Pub/Sub
Here you can find a related question link.