如何在S3存储桶中仅获取一个级别的对象? [英] How can I get only one level of objects in a S3 bucket?
问题描述
我只想列出存储桶中本身不是存储桶的对象.有没有一种方法可以解析出ListBucket的结果呢?
I want to list only the objects in a bucket that aren't buckets themselves. Is there a way of doing this short of parsing out the results of ListBucket?
推荐答案
不是存储桶本身的存储桶中的对象
objects in a bucket that aren't buckets themselves
存储桶不能包含其他存储桶.你是说文件夹吗?S3也没有文件夹的概念.
Buckets can't contain other buckets. Do you mean folders? S3 doesn't have a concept of folders either.
每个S3帐户可以有100个存储桶,每个存储桶可以包含无限数量的对象/文件.如果使用文件名中的/
命名文件,则AWS GUI工具(例如AWS Console,BucketExplorer等)会将每个部分解释为虚拟文件夹.例如
You can have 100 buckets per S3 account and each bucket can contain an unlimited number of objects/files. If you name your files with /
's in the filename, the AWS GUI tools (eg AWS Console, BucketExplorer etc) will interpret each section as a virtual folder. eg
名为 folder1/folder2/myfile.jpg
的文件将作为具有该名称的平面"文件存储在S3中,但是在GUI工具中,它看起来就像是名为的文件一样> myfile.jpg
在 folder1/folder2
中向下2个子文件夹.
A file named folder1/folder2/myfile.jpg
will be stored in S3 as a 'flat' file with that name, but in the GUI tools it will appear as though a file named myfile.jpg
is 2 subfolders down in folder1/folder2
.
您可以使用 prefix
和 delimiter
参数来解析
You can use the prefix
and delimiter
parameters to parse the results of a GET Bucket (List Objects) call. The same options are available in any of the SDKs too.
更新以回答评论.
假设我们的S3存储桶如下所示:
Assuming our S3 bucket looks like this:
mybucket
folder1
file1.txt
file2.txt
folder2
file3.txt
file4.txt
folder3
file5.txt
file6.txt
使用 prefix ="folder1/"
将返回所有6个文件: file1.txt
至 file6.txt
.
使用 前缀="folder1/"
和 定界符="/"
将返回2个文件:
Using a prefix = "folder1/"
and a delimiter = "/"
would return 2 files:
file1.txt
file2.txt
和包含的响应的 CommonPrefixes
集合
folder1/folder2/
folder1/folder3/
这篇关于如何在S3存储桶中仅获取一个级别的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!