Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Space size #49

Closed
UFO-84 opened this issue Oct 7, 2020 · 3 comments
Closed

Space size #49

UFO-84 opened this issue Oct 7, 2020 · 3 comments

Comments

@UFO-84
Copy link

UFO-84 commented Oct 7, 2020

Is there any way to get total space used in a space using your API?

@SociallyDev
Copy link
Owner

Hey,
So there is a way to get the entire Space's storage size. It involves iterating over all the objects that exist in the bucket to get the total size:

$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");


$size = 0;
foreach ($my_space->listFiles() as $file) {
  $size += $file["Size"];
}

//$size should hold the total bucket total size.

@UFO-84
Copy link
Author

UFO-84 commented Oct 8, 2020

Thanks for the quick reply.

The way you mentioned will do the job but if I have huge objects in the space, it will be a pain.

Anyway, thanks again. I will make a cron/queue process to maintain space size.

@UFO-84 UFO-84 closed this as completed Oct 8, 2020
@SociallyDev
Copy link
Owner

Yes, I know. Unfortunately, this is the only method possible because I don't think there is a general object that lets you know the total size of a Space, and DigitalOcean's own API has no references to it either.

Another thing you could do is keep a tally of total size in your own database (Increased whenever you upload an object, decreased whenever you delete one).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants