How to get size of S3 Object without downloading it?

968 views
Skip to first unread message

John David Eriksen

unread,
Aug 24, 2010, 7:43:04 PM8/24/10
to jclouds-dev
Hi, we are trying to implement a progress bar. In order for this
progress bar to work, we need to obtain the size of a file stored in
S3. We have no way to precalculate this value.

The S3 API exposes a HEAD operation on objects that can retrieve the
object's size:
http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectHEAD.html

I suspect that Ruby AWS::S3 uses this technique:
http://amazon.rubyforge.org/doc/classes/AWS/S3/S3Object.html#M000055

I looked through blobstore.clj but did not find a way to obtain an
object's size without downloading it first.

I've also looked through S3Object documentation and did not notice any
mentions of this functionality:
http://code.google.com/p/jclouds/wiki/S3Object

Is there some way, via blobstore.clj or other jclouds functionality,
to obtain this information?

Thanks!

John David

Adrian Cole

unread,
Aug 24, 2010, 8:05:46 PM8/24/10
to jclou...@googlegroups.com
Hi, John David.

You can portably get this through the BlobStore interface.

In java, it is
   BlobMetadata blobMetadata(String container, String name);

in clojure, it is:
   blob-metadata

I hope this helps!
-Adrian


--
You received this message because you are subscribed to the Google Groups "jclouds-dev" group.
To post to this group, send email to jclou...@googlegroups.com.
To unsubscribe from this group, send email to jclouds-dev...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jclouds-dev?hl=en.


Adrian Cole

unread,
Aug 24, 2010, 8:11:50 PM8/24/10
to jclou...@googlegroups.com
p.s. the wiki you should be looking at is:
http://code.google.com/p/jclouds/wiki/BlobStore

I've authorized you to make any corrections :)

thanks.
-a

John David Eriksen

unread,
Aug 25, 2010, 10:54:32 AM8/25/10
to jclouds-dev
Hey Adrian,

You were right:

user> (with-s3 (map #(.getName %) (.getMethods (class (blob-metadata
"my-container" "my-file.csv")))))
("getContentType" "setContentType" "getContentMD5" "setContentMD5"
"getType" "getSize" "setSize" "setLastModified" "getLastModified"
"getETag" "setETag" "hashCode" "equals" "compareTo" "compareTo"
"toString" "getName" "getLocation" "setName" "getType" "setType"
"getProviderId" "getUri" "getUserMetadata" "setId" "setLocation"
"setUri" "setUserMetadata" "wait" "wait" "wait" "getClass" "notify"
"notifyAll")
user> (with-s3 (.getSize (blob-metadata "my-container.csv" "my-
file.csv")))
585569425

Sorry, I was under the impression that blob-metadata's purpose was
retrieval of user-defined metadata.

Thanks for your help!

John David

On Aug 24, 6:05 pm, Adrian Cole <adrian.f.c...@gmail.com> wrote:
> Hi, John David.
>
> You can portably get this through the BlobStore interface.
>
> In java, it is
>    BlobMetadata blobMetadata(String container, String name);
>
> in clojure, it is:
>    blob-metadata
>
> I hope this helps!
> -Adrian
>
> On Tue, Aug 24, 2010 at 4:43 PM, John David Eriksen <jknd...@gmail.com>wrote:> Hi, we are trying to implement a progress bar. In order for this
> > progress bar to work, we need to obtain the size of a file stored in
> > S3. We have no way to precalculate this value.
>
> > The S3 API exposes a HEAD operation on objects that can retrieve the
> > object's size:
> >http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectHEAD....
>
> > I suspect that Ruby AWS::S3 uses this technique:
> >http://amazon.rubyforge.org/doc/classes/AWS/S3/S3Object.html#M000055
>
> > I looked through blobstore.clj but did not find a way to obtain an
> > object's size without downloading it first.
>
> > I've also looked through S3Object documentation and did not notice any
> > mentions of this functionality:
> >http://code.google.com/p/jclouds/wiki/S3Object
>
> > Is there some way, via blobstore.clj or other jclouds functionality,
> > to obtain this information?
>
> > Thanks!
>
> > John David
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "jclouds-dev" group.
> > To post to this group, send email to jclou...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > jclouds-dev...@googlegroups.com<jclouds-dev%2Bunsu...@googlegroups.com>
> > .
Reply all
Reply to author
Forward
0 new messages