How to get space consumed by folders in the bucket using API?


I have bucket created in Space and it will have many folder in it.I want to get the space consumed by each folder using API.Is there any api to get the space related to all folder inside the bucket.

Thanks, vimal


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

In order to be compatible with existing tools, the Spaces API was designed to be inter-operable with the S3 API. Unfortunately, there is not a specific API call that will return that information, but when you list the contents of a bucket with the API it displays the size of each object. So the information can be calculated.

The easiest way to do this is to use an existing tool like s3cmd. (See here for installation and configuration instructions.) For example:

$ s3cmd du s3://my-bucket
392431   9 objects s3://my-bucket/
$ s3cmd du s3://my-bucket/foo/
68209    5 objects s3://my-bucket/foo/

Another thing that is helpful to understand is that there is no real concept of a folder in the S3 API. When you create a “folder” through the Spaces UI, it is actually just a “key” with a zero sized “object.” Items inside the folder have the folder key as a prefix to their own key. For example, notice the file sizes when I list the full contents of the bucket:

$ s3cmd ls -r s3://my-bucket
2017-10-19 14:01    288835   s3://my-bucket/screencast.mp4
2017-07-13 18:40        14   s3://my-bucket/example.txt
2018-07-13 16:09         4   s3://my-bucket/foo
2017-08-03 21:05         0   s3://my-bucket/foo/
2017-08-03 21:08         0   s3://my-bucket/foo/bar/
2017-08-03 21:08     31719   s3://my-bucket/foo/bar/image.png
2017-08-03 21:06      1121   s3://my-bucket/foo/config.yml.enc
2018-05-08 17:55     35369   s3://my-bucket/foo/sammy.png
2018-05-08 17:39     35369   s3://my-bucket/sammy.png