【问题标题】:Fog/aws gem for IBM Cloud Object Storage is not workingIBM Cloud Object Storage 的 Fog/aws gem 不工作
【发布时间】:2020-04-10 05:49:57
【问题描述】:

由于 Softlayer 或 IBM Cloud 已从基于 Swift 的对象存储迁移到基于 S3 的云对象存储。我正在使用雾/aws 而不是雾/softlayer。

下面是代码:

require 'fog/aws'
fog_properties = {
  provider: 'AWS',
  aws_access_key_id: username,
  aws_secret_access_key: api_key
}
@client = Fog::Storage.new(fog_properties)
@client.directories

但即使使用有效的密钥和 id 也失败了。


<Error><Code>InvalidAccessKeyId</Code><Message>The AWS Access Key Id you provided does not exist in our records.\</Message><AWSAccessKeyId>####</AWSAccessKeyId><RequestId>####</RequestId><HostId>##</HostId></Error>

IBM COS 使用的端点是“https://control.cloud-object-storage.cloud.ibm.com/v2/endpoints

当我尝试单独使用雾时(需要“雾”)。它抛出以下错误:

Unable to activate google-api-client-0.23.9, because mime-types-2.99.3 conflicts with mime-types (~&gt; 3.0) (Gem::ConflictError)

请建议如何解决这些问题。

【问题讨论】:

    标签: ruby ibm-cloud-infrastructure fog object-storage ibm-cloud-storage


    【解决方案1】:

    https://control.cloud-object-storage.cloud.ibm.com/v2/endpoints" 这不是端点,而是 JSON 中的端点列表。

    为您的存储桶位置选择端点。 例如,如果您的存储桶位于 us-south,则公共端点为 https://s3.us-south.cloud-object-storage.appdomain.cloud

    【讨论】:

      【解决方案2】:

      以下代码适用于 IBM Cloud Objects Storage

      properties = {
                region: region,
                endpoint: URI('https://s3.us-south.cloud-object-storage.appdomain.cloud'),
                credentials: Aws::Credentials.new(access_key_id, secret_access_key)
              }
              Aws.config.update(properties)
              @client = Aws::S3::Client.new
      

      配置的属性也可以设置为 ENV 变量。

      以下是对 COS 执行的一些基本操作。

      列出所有的 bucker 名称

      @client.list_buckets.buckets.map(&:name)

      创建存储桶

      @client.create_bucket(bucket: )

      上传文件

      @client.put_object(bucket: , key: , body: )

      下载文件

      @client.get_object(bucket: , key:)

      删除文件

      @client.delete_object(bucket: , key:)

      删除存储桶

      @client.delete_bucket(bucket: )

      【讨论】:

        猜你喜欢
        • 2018-08-28
        • 1970-01-01
        • 2020-03-19
        • 1970-01-01
        • 2018-06-05
        • 2018-05-28
        • 2018-12-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多