0

Is it possible to grab the size of a cloudfiles object without retrieving the whole object?

I have 500,000 files that I want to know the byte size of, but if I request the whole object on each one it will cost me $100 in bandwidth charges.

I know I can get a list of objects in a container, but that only seems to give me the name of the objects?

Thanks, and help appreciated.

Codemonkey
  • 4,455
  • 5
  • 44
  • 76

1 Answers1

2

Using the PHP SDK, you have a couple of options:

  1. If you are looking for the size of each file, you can retrieve the list of files in a container first, then loop over them, call the getContentLength() method on each file in the loop.

  2. If you are looking for the total size taken up by all your 500,000 files, you can simply get the size of the container(s) they are in. Here is the code for that: https://github.com/rackspace/php-opencloud/blob/master/docs/userguide/ObjectStore/USERGUIDE.md#get-bytes-used.

Shaunak Kashyap
  • 598
  • 3
  • 6
  • I'm using the (deprecated, I think) Rackspace Cloud Files API. So I need to switch to the opencloud API maybe? – Codemonkey Apr 10 '14 at 16:20
  • Actually it seems that get_objects returns an array of objects each of which has the property content_length. For some reason I get an error "call to undefined function json_decode()" but hopefully once I fix that all will be good. – Codemonkey Apr 10 '14 at 16:22
  • Bingo, that's done it. I'm going to accept your answer anyway, even though it's not the way I went... thanks for you time! – Codemonkey Apr 10 '14 at 16:25
  • Oh and if anyone has the same json_decode problem, the fix is "yum search json" and then install the relevant looking package. In my case php55u-pecl-jsonc – Codemonkey Apr 10 '14 at 16:26