0

我正在尝试遍历 AWS::S3::Tree 对象的子对象,如下所示:

conn = AWS::S3.new(:access_key_id => 'ACCESSKEYID', :secret_access_key => 'ACCESSKEY')
bucket = conn.buckets['bucketname']
tree = bucket.objects.with_prefix('assets/images').as_tree
directories = tree.children.select(&:branch?).collect(&:prefix)

这在我用作前缀的大多数路径上都可以正常工作,但是一个文件夹(具有数万个子文件夹)会返回此错误:

/lib/aws/s3/object_collection.rb:311:in `next_markers': Unable to find marker in S3 list objects response (RuntimeError)

我已经重写了 gem 方法来调试,如下所示:

module AWS
class S3
    class ObjectCollection
        protected
        def next_markers page

            raise page.inspect

            marker = (last = page.contents.last and last.key)
            if marker.nil?
                raise 'Unable to find marker in S3 list objects response xxxxx'
            else
                { :marker => marker }
            end
        end
    end
  end
end

这将输出返回的数据:

{:delimiter=>"/", :contents=>[], :common_prefixes=>[{:prefix=>"assets/images/100/"}, {:prefix=>"assets/images/1000/"}, {:prefix=>"assets/images/1001/"}, etc etc

为什么调用为 :contents 返回一个空数组?

4

1 回答 1

1

当来自 S3 的 XML 无效并且无法解析内容时,就会发生这种情况。如果您启用了线跟踪(将 :http_wire_trace => true 添加到 AWS::S3.new)并且您应该能够检查有问题的 http 响应正文。

于 2012-12-29T02:37:10.920 回答