0

I am trying to calculate the total size of an S3 bucket using my Java Spring MVC web application. I am using jets3tfor my S3 access.

I have the following method to calculate the total file size of an S3 bucket.

public Long getBucketSize(String accessKeyId, String secretAccessKey, String bucketname) throws IOException, S3ServiceException 
{
    AWSCredentials awsCredentials = 
            new AWSCredentials(accessKeyId, secretAccessKey);
    S3Service s3Service = new RestS3Service(awsCredentials);
    S3Object[] objects = s3Service.listObjects(bucketname);
    if(objects != null) 
    {
        for (S3Object s3Object : objects) 
        {

        }
    }
    return null;
}

But I cannot find any way to calculate the total file size of a bucket. Is there any way to find that?

Geo Thomas
  • 1,139
  • 3
  • 26
  • 59
  • 1
    hmm, there is no easy way to get the size, you can just iterate through files and get the size from metadata (Content-Length property) – nafas Jul 31 '18 at 11:43
  • @nafas, Content-Length is a long value, is there any way to get the size in MB – Geo Thomas Jul 31 '18 at 12:17
  • 1
    mate, content-length, is the number of bytes, to get the size in MB you can divide the value by 2^20 (ofcourse you should consider the floating values too) – nafas Jul 31 '18 at 12:20

0 Answers0