检查文件夹是否存在于 s3 存储桶中 [英] Check if folder exist in s3 bucket
问题描述
如何使用 Ruby on Rails 检查我的 s3 存储桶中是否存在某个文件夹?
我正在使用 AWS:S3 官方 gem初始化全局连接后
AWS::S3::Base.establish_connection!(:access_key_id => 'my_key_id', :secret_access_key => 'my_secret')
我的存储桶名为:myfirstbucket
文件夹内命名为:my_folder
my_folder 中的文件名为:my_pic.jpg
当我尝试检查 my_pic.jpg
是否存在时,它工作得很好
s3object.exists?/my_folder/my_pic.jpg",myfirstbucket"=>真的
如何只检查文件夹是否存在?
s3object = AWS::S3::S3Objects3object.exists?/my_folder/"、myfirstbucket"=>错误的
Use Bucket#objects
:
bucket.objects({prefix: 'my/folder/'}).limit(1).any?
<块引用>
返回 ObjectSummary
资源的 Collection
.没有 API 请求直到您调用集合上的可枚举方法.Client#list_objects
将被多次调用,直到每个ObjectSummary
已生成.
—http://docs.aws.amazon.com/sdkforruby/api/Aws/S3/Bucket.html#objects-instance_method
How can I check if some folder exists in my s3 bucket using Ruby on Rails?
I’m using AWS:S3 official gem After initializing the global connection
AWS::S3::Base.establish_connection!(:access_key_id => 'my_key_id', :secret_access_key => ‘my_secret’)
I have bucket named: myfirstbucket
With folder inside named: my_folder
With file inside my_folder named: my_pic.jpg
When I try to check if my_pic.jpg
exist it work just fine
s3object.exists? "/my_folder/my_pic.jpg" , "myfirstbucket"
=> True
How can I check only if the folder exists?
s3object = AWS::S3::S3Object
s3object.exists? "/my_folder/" , "myfirstbucket"
=> False
Use Bucket#objects
:
bucket.objects({prefix: 'my/folder/'}).limit(1).any?
Returns a
Collection
ofObjectSummary
resources. No API requests are made until you call an enumerable method on the collection.Client#list_objects
will be called multiple times until everyObjectSummary
has been yielded.—http://docs.aws.amazon.com/sdkforruby/api/Aws/S3/Bucket.html#objects-instance_method
这篇关于检查文件夹是否存在于 s3 存储桶中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!