简体   繁体   English

如何使用Ruby中的Fog列出S3文件夹中的所有文件

[英]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.

相关问题 如何使用Ruby中的雾复制s3文件夹中的所有文件 - How to copy all files in a folder on s3 using Fog in Ruby 如何在 ruby​​ on rails 中使用 AWS-SDK gem 列出 s3 文件夹中的所有文件 - How to list all files in an s3 folder using AWS-SDK gem in ruby on rails Ruby-使用fog将内容附加到现有s3文件的末尾 - Ruby - Append content at the end of the existing s3 file using fog 如何在 Ruby 中将所有文件和子文件夹从一个文件夹复制到同一 AWS S3 存储桶中的另一个文件夹 - How do I copy all Files and Sub-Folders from One Folder to another Folder in same AWS S3 bucket in Ruby 如何使用 ruby 中的 Google Drive api 获取 Google Drive 上文件夹内所有文件的列表 - How to get list of all files inside a folder on Google Drive using Google Drive api in ruby 如何使用Ruby使用GPG在S3中流式传输和解密大文件 - How to stream and decrypt large files in S3 with GPG using Ruby 如何使用AWS Ruby SDK从具有特定名称的各种子文件夹的S3文件夹中删除超过n天的所有对象 - How to delete all objects from a S3 folder of various sub folder with Specific name which are older than n days using AWS Ruby SDK Ruby on Rails PaperClip - 如何将文件存储在除S3或公共文件夹之外的其他位置 - Ruby on Rails PaperClip - How to store files in another location besides S3 or the public folder S3雾读进度 - S3 Read Progress with Fog 如何使用雾从Amazon S3检索具有Unicode名称的文件 - How to retrieve file with unicode name from Amazon S3 with fog
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM