0

I am reading this link http://docs.aws.amazon.com/AmazonS3/2006-03-01/API/RESTBucketGET.html

The example i want to use is this

The following GET request specifies the delimiter parameter with value "/", and the prefix parameter with value photos/2006/.

The response is

GET /?prefix=photos/2006/&delimiter=/ HTTP/1.1
Host: example-bucket.s3.amazonaws.com
Date: Wed, 01 Mar  2009 12:00:00 GMT
Authorization: AWS AKIAIOSFODNN7EXAMPLE:xQE0diMbLRepdf3YB+FIEXAMPLE=

The returned resposne is

<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
  <Name>example-bucket</Name>
  <Prefix>photos/2006/</Prefix>
  <Marker></Marker>
  <MaxKeys>1000</MaxKeys>
  <Delimiter>/</Delimiter>
  <IsTruncated>false</IsTruncated>

  <CommonPrefixes>
    <Prefix>photos/2006/feb/</Prefix>
  </CommonPrefixes>
  <CommonPrefixes>
    <Prefix>photos/2006/jan/</Prefix>
  </CommonPrefixes>
</ListBucketResult>

I get that but i am not sure how can i implement that in django/python using boto.

Also Is there any way to get JOSN instead of xml.

4

1 回答 1

2

在 boto 中,您可以创建一个类似的请求,如下所示:

import boto

s3 = boto.connect_s3()
bucket = s3.lookup('example-bucket')
for key in bucket.list(prefix='photos/2006/', delimiter='/'):
    print k.name

boto 所做的是解析来自 S3 的 XML 输出并将其转换为 Python 对象。因此,列出一个存储桶将返回一堆 Key 对象,每个对象代表 S3 中的一个对象。

boto 或 S3 中没有任何东西可以自动将数据转换为 JSON,但您当然可以编写一些 Python 将 Key 对象中的信息转换为 JSON。

于 2013-06-20T11:43:07.793 回答