Offset-Range Requests to S3 using boto

1,291 views
Skip to first unread message

znjp

unread,
Jul 29, 2011, 2:38:36 PM7/29/11
to boto-users

Is it possible to request an offset and range of an S3 object, opposed
to the entire object? e.g. Request the first 4K of a 1GB object?

I believe the Amazon S3 API supports this, but reading through the
boto docs and examples, it's not clear to me how to achieve it.

Thanks!

-znjp

Mitchell Garnaat

unread,
Jul 29, 2011, 2:57:32 PM7/29/11
to boto-...@googlegroups.com
Yes, it is possible to use range requests in boto.  Here's a quick example:

>>> import boto
>>> s3 = boto.connect_s3()
>>> bucket = s3.lookup('mybucket')
>>> key = bucket.lookup('mykey')
>>> first10 = key.get_contents_as_string(headers={'Range' : 'bytes=0-9'})
>>> len(first10)
10

It might make sense to add a convenience method to make all of this a bit easier.  Not sure.  But it is doable now.

Mitch


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


znjp

unread,
Jul 29, 2011, 4:12:48 PM7/29/11
to boto-users
Awesome. Thanks.

-znjp

Fayaz Yusuf Khan

unread,
Jul 31, 2011, 10:17:57 AM7/31/11
to boto-...@googlegroups.com
On Saturday 30 Jul 2011 12:27:32 AM Mitchell Garnaat wrote:
> Yes, it is possible to use range requests in boto. Here's a quick example:
> >>> import boto
> >>> s3 = boto.connect_s3()
> >>> bucket = s3.lookup('mybucket')
> >>> key = bucket.lookup('mykey')
> >>> first10 = key.get_contents_as_string(headers={'Range' : 'bytes=0-9'})
> >>> len(first10)
>
> 10
>
> It might make sense to add a convenience method to make all of this a bit
> easier. Not sure. But it is doable now.

Perhaps something like, "key.get_contents_as_string[0:9]"? :D

--
Fayaz Yusuf Khan
Cloud developer and designer
Dexetra SS, Kochi, India
fayaz.yusuf.khan_AT_gmail_DOT_com
fayaz_AT_dexetra_DOT_com
+91-9746-830-823

signature.asc

Rushi Agrawal

unread,
Mar 12, 2014, 3:29:49 AM3/12/14
to boto-...@googlegroups.com, mi...@garnaat.com
I am strongly in favour of adding parameters for this specific task to the methods including get_contents_as_string. Implementation of such thing plus documenting it in the docstring will make the life easier of the first-time boto users as they'll be able to find this rightaway from the docs, and won't need to search for the same on the internet, and then reach here to get the answer.

Also, I'm willing to implement this feature. Is an issue already created for this task?
Reply all
Reply to author
Forward
0 new messages