By subhadeep422
Hi,
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
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
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
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.