加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby – 如何检查AWS S3bucket中是否存在资源

发布时间:2020-12-17 02:48:53 所属栏目:百科 来源:网络整理
导读:我有一个AWS S3存储桶,我有多个文件夹. s3 = AWS::S3.newbucket = s3.buckets['test']bucket.exists? = true 假设我有一个名为demo / index.html的资源,我将如何检查此资源中是否存在此资源? 可能是我的问题太简单了,但我无法为此找到合适的答案.任何帮助表
我有一个AWS S3存储桶,我有多个文件夹.

s3 = AWS::S3.new
bucket =  s3.buckets['test']
bucket.exists? => true

假设我有一个名为demo / index.html的资源,我将如何检查此资源中是否存在此资源?

可能是我的问题太简单了,但我无法为此找到合适的答案.任何帮助表示赞赏.

解决方法

#exists? ?布尔值

Returns true if the object exists in S3.

# new object,does not exist yet
obj = bucket.objects["my-text-object"]
# no instruction file present
begin
  bucket.objects['my-text-object.instruction'].exists? #=> false
rescue
  # exists? can raise an error `Aws::S3::Errors::Forbidden`
end


# store the encryption materials in the instruction file
# instead of obj#metadata
obj.write("MY TEXT",:encryption_key => MY_KEY,:encryption_materials_location => :instruction_file)

begin
  bucket.objects['my-text-object.instruction'].exists? #=> true
rescue
  # exists? can raise an error `Aws::S3::Errors::Forbidden`
end

http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/S3/S3Object.html#exists%3F-instance_method

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读