【问题标题】:How to list files in a Google Storage bucket with fog-google如何使用雾谷歌列出谷歌存储桶中的文件
【发布时间】:2016-04-12 21:35:53
【问题描述】:

使用fog-googleJSON API,如何列出具有给定前缀的存储桶中的文件?

这挂了:

require 'fog/google'
storage = Fog::Storage.new(:provider => 'Google', :google_project => project, :google_json_key_string => json_data)
storage.directories.get(bucket_name, prefix: prefix).files

在 S3 上使用 fog-aws 的类似任务工作正常:

require 'fog/aws'
storage = Fog::Storage.new(provider: 'AWS', aws_access_key_id: aws_access_key_id, aws_secret_access_key: aws_secret_access_key)
storage.directories.get(bucket_name, prefix: prefix).files.each do |f|
  puts f.key
end

在上面的两个代码sn-ps中,假设相关变量设置正确。

【问题讨论】:

    标签: fog fog-google


    【解决方案1】:

    在此处按照 Google 说明进行操作:

    [https://cloud.google.com/ruby/getting-started/using-cloud-storage][1]

    FogStorage = Fog::Storage.new(provider: "Google",  
       google_storage_access_key_id:     config["access_key_id"],  
       google_storage_secret_access_key: config["secret_access_key"] )
    
    StorageBucket = FogStorage.directories.new key: config["bucket"]
    puts StorageBucket.files.inspect
    

    我认为你的问题出在 FogStorage.directories.new

    【讨论】:

    • 使用 google_json_key_string,无法使用 google_storage_access_key_id。
    猜你喜欢
    • 2020-07-02
    • 1970-01-01
    • 2021-12-23
    • 1970-01-01
    • 2020-06-01
    • 2019-02-09
    • 1970-01-01
    • 2020-12-21
    • 1970-01-01
    相关资源
    最近更新 更多