检查s3存储桶上是否存在特定文件夹

时间:2017-10-04 08:57:34

标签: ruby-on-rails ruby amazon-s3 fog

我正在使用Fog Storage将我的文件上传到s3。我必须检查文件夹是否存在。我不需要前缀函数,因为它检查启动。我需要一些准确匹配文件夹名称的东西

s3的结构

mynewbucket(bucketname)
nhdata-231(folder or directory name)
rsadata-56787(folder or directory name)
pfadata-1456(folder or directory name)

我必须检查是否存在特定文件夹。我正在分享我的代码

  s3 = Fog::Storage.new({
                :provider                 => 'AWS',
                :aws_access_key_id        => ENV["ACCESSKEYID"],
                :aws_secret_access_key    => ENV["SECRETACCESSKEY"],
                :region                   => 'us-east-2'
             })

    directory = s3.directories.get(ENV["BUCKET"])
//Here I have to check before creating any folder whether it exist or not.
                file = directory.files.create(key: full_bucket_path, public: true)
                file.body = image_contents
                file.save
                file.public_url

0 个答案:

没有答案