AWS SDK PHP上市S3文件夹 [英] aws sdk php for listing s3 folders

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

问题描述

几件事情我知道。 文件夹是不是S3的概念,他们仅仅是与主要的名称使用'/'作为prefixes一个零字节的对象。假设我们打电话给他们的文件夹和文件进行简单将使我的问题容易短语。

few things I do know. Folders are not a concept of S3 they are merely a zero byte object with key names that use the '/' as prefixes. Assuming that we call them folders and files for simplicity would make my question easier to phrase.

这是可以做到一个S3-> get_object_list(..)与preFIX =根/,并让所有的文件/文件夹。我的问题是这样的。

It is possible to do a s3->get_object_list(..) with prefix ="root/" and get all the files/folders. My problem is this.

鉴于文件夹和子文件夹的如列表

Given a list of folders and subfolders for e.g.

root/  
root/folder1/  
root/folder1/file1.txt  
root/folder2/ 
root/folder3/file2.txt

如何只列出的文件夹。我希望prevent列出的所有文件(即使是在回应它们不需要被退回),但get_object_list在PHP不支持目前常见的prefixes参考:的 http://docs.amazonwebservices.com/AWSSDKforPHP/latest/#m=AmazonS3/get_object_list 尽管医生说这样的code显然不使用分隔符实际上将只能返回在根文件夹中的文件(preFIX)

How can i list only the folders. I was hoping to prevent listing all files (even in response they need not be returned) but get_object_list in php does not current support commonPrefixes ref: http://docs.amazonwebservices.com/AWSSDKforPHP/latest/#m=AmazonS3/get_object_list even though the doc says so the code clearly does not and using the delimiter will actually only return files in the root folder (prefix)

我想知道是否有人使用了基于帮助这样的情况任何技术后响应或请求。

I am wondering if anyone has used any technique post-response or request based to help with such a situation.

我已经尝试了preFIX,分隔符和标记我能想到的每一个组合。并非如此,PCRE但相信我可以用我只有一个级别深的文件夹,但我不知道如何构建一个用于这种情况不错。由于我的要求不工作我继续接受的所有文件和文件夹的响应,希望梳理出来在PHP ...我这样想着

I have already tried every combo of prefix,delimiter and marker i could think of. Not so good with PCRE but sure I could use that I only have one level deep folders but I don't know how to construct one for this case. Since my requests were not working I proceeded to accept the response with all files and folders and hopefully sort it out in php... or so I thought

我已经试过后响应: 目录名() - 没有用错过了某些文件夹(空的),相信我能删除重复的数组,但存在遗漏的文件夹的问题 PATHINFO() - 的行为方式相同目录名(),假设所有路径结束与文件名。 水珠 - 没有运气,同上

I have tried in post response: dirname() - no use misses out some folders (empty ones), sure I can remove duplicates in array but the problem of missed folder exists pathinfo() - behaves the same way as dirname(), assumes that all paths end with filename. glob - no luck, same as above.

既然我已经浪费了半天时间在这我希望有人已经处理了这一点,并会愿意分享:

Since I have already wasted half a day on this I am hoping someone has dealt with this and would care to share:

请注意:我没有问题,Python和博托这样做。但是,这是不是Python和我不得不这样做在PHP为这个项目。

note: I have no problem doing this in python and boto. But this is not python and I have to do this in PHP for this project.

推荐答案

您已经糊涂 get_object_list() list_objects()。请参阅: https://forums.aws.amazon.com/thread .jspa主题ID = 106277&放大器; TSTART = 0

You've confused get_object_list() with list_objects(). See: https://forums.aws.amazon.com/thread.jspa?threadID=106277&tstart=0

这篇关于AWS SDK PHP上市S3文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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