【问题标题】:accessing non standard s3 bucket访问非标准 s3 存储桶
【发布时间】:2013-06-20 15:18:39
【问题描述】:

使用aws-s3 gem,我可以使用标准 s3 存储桶成功执行交易,但爱尔兰制造的一个 (s3-eu-west-1) 给出错误The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint. 经过 2 小时的搜索后,这仍然没有任何意义我,有没有办法解决这个问题。

这个simple tutorial 适用于标准 s3 存储桶,但不适用于爱尔兰。

这个person's experiences 似乎暗示这是不可能的。

【问题讨论】:

    标签: ruby amazon-s3


    【解决方案1】:

    好的,我刚刚找到the answer here

    require 'aws/s3'
    AWS::S3::Base.establish_connection!(
      :access_key_id     => ACCESS_KEY_ID,
      :secret_access_key => SECRET_ACCESS_KEY
    )
    AWS::S3::DEFAULT_HOST.replace('s3-eu-west-1.amazonaws.com')  # <= the crucial hacky line
    AWS::S3::S3Object.store(
      file_name,
      temp_file,
      bucket,
      :content_type => mime_type
    )
    

    编辑

    Much better option 是使用aws-sdk gem,它的 API 看起来更好,例如:

    require 'aws-sdk'
    s3 = AWS::S3.new(
        :access_key_id => ACCESS_KEY_ID,
        :secret_access_key => SECRET_ACCESS_KEY,
        :s3_endpoint => 's3-eu-west-1.amazonaws.com'
    )
    bucket = s3.buckets[bucket_name]
    bucket.objects.create(
      file_name,
      temp_file,
      :content_type => mime_type
    )
    

    【讨论】:

      猜你喜欢
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-16
      • 2020-01-14
      相关资源
      最近更新 更多