访问非标准s3存储桶

时间:2013-06-20 15:18:40

标签: ruby amazon-s3

使用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似乎表明这是不可能的。

1 个答案:

答案 0 :(得分:6)

好的,我刚刚找到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将使用其API似乎更好的aws-sdk gem,例如:

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
)