[英]How to list all files in an S3 folder using Fog in Ruby
How do I list all the files in a specific S3 "directory" using Fog? 如何使用Fog列出特定S3“目录”中的所有文件?
I know that S3 doesn't store files in folders but I need a way to limit the returned files to specific "folder" instead of retrieving the entire list in the bucket. 我知道S3不会将文件存储在文件夹中,但我需要一种方法将返回的文件限制为特定的“文件夹”,而不是检索存储桶中的整个列表。
Use the prefix
option on the directory.get method. 使用directory.get方法上的
prefix
选项。 Example: 例:
def get_files(path, options)
connection = Fog::Storage.new(
provider: 'AWS',
aws_access_key_id: options[:key],
aws_secret_access_key: options[:secret]
)
connection.directories.get(options[:bucket], prefix: path).files.map do |file|
file.key
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.