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不会将文件存储在文件夹中,但我需要一种方法将返回的文件限制为特定的“文件夹”,而不是检索存储桶中的整个列表。
1 个解决方案
#1
38
Use the prefix
option on the directory.get method. Example:
使用directory.get方法上的prefix选项。例:
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
#1
38
Use the prefix
option on the directory.get method. Example:
使用directory.get方法上的prefix选项。例:
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