在Amazon S3上的文件夹中遍历对象 [英] Iterating over the objects in a folder on amazon S3

查看:2421
本文介绍了在Amazon S3上的文件夹中遍历对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个应用程序,用户可以创建自己的网页和盎然使用S3来存储页面,因为它们是static.Here,因为我们有每个用户的100桶的限制举办,我们决定一起去文件夹的桶内每个用户。

We have an application where in user can create his own webpages and host them.We are using S3 to store the pages as they are static.Here,as we have a limitation of 100 buckets per user,we decided to go with folders for each user inside a bucket.

现在,如果用户想举办自己的网站上他的领地,我们问他的域名(他开始的时候,我们发表我们的子域的),我要重命名文件夹。

Now,if a user wants to host his website on his domain,we ask him for the domain name(when he starts we publish it on our subdomain) and I have to rename the folder.

S3是我知道一个平面文件系统实际上有没有文件夹只是分隔符 / 分隔值,所以我不能进入该文件夹,并检查了多少页包含。该API允许其一个接一个,但对于我们要知道,在斗对象名称。

S3 being a flat file system I know there are actually no folders but just delimeter / separated values so I cannot go into the folder and check how many pages it contains.The API allows it one by one but for that we have to know the object names in the bucket.

我经历了文档和遇到的迭代器的,我还没有实现yet.This其中采用狂饮我没有经验和面临的挑战,在实施

I went through the docs and came across iterators,which I have not implemented yet.This uses guzzle of which I have no experience and facing challenges in implementing

是否有任何其他的路径,我可以采取或我需要走这条路。

Is there any other path I can take or I need to go this way.

推荐答案

您可以通过以下操作创建一个迭代器的文件夹中的内容:

You can create an iterator for the contents of a "folder" by doing the following:

$objects = $s3->getIterator('ListObjects', array(
    'Bucket'    => 'bucket-name',
    'Prefix'    => 'subfolder-name/',
    'Delimiter' => '/',
));

foreach ($objects as $object) {
    // Do things with each object
}

如果你只需要一个数,你可以这样:

If you just need a count, you could this:

echo iterator_count($s3->getIterator('ListObjects', array(
    'Bucket'    => 'bucket-name',
    'Prefix'    => 'subfolder-name/',
    'Delimiter' => '/',
)));

这篇关于在Amazon S3上的文件夹中遍历对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆