如何检查 AWS S3bucket 中是否存在资源
How to check if a resource exists in an AWS S3bucket
我有一个 AWS S3 存储桶,其中有多个文件夹。
s3 = AWS::S3.new
bucket = s3.buckets['test']
bucket.exists? => true
假设我有一个名为 demo/index.html
的资源,我将如何检查此资源是否存在于 this bucket
中?
可能是我的问题太简单了,但我找不到合适的答案。感谢任何帮助。
#存在吗? ⇒ 布尔值
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
我有一个 AWS S3 存储桶,其中有多个文件夹。
s3 = AWS::S3.new
bucket = s3.buckets['test']
bucket.exists? => true
假设我有一个名为 demo/index.html
的资源,我将如何检查此资源是否存在于 this bucket
中?
可能是我的问题太简单了,但我找不到合适的答案。感谢任何帮助。
#存在吗? ⇒ 布尔值
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