gpt4 book ai didi

ruby-on-rails - Rails4.1 : AWS errors missing region

转载 作者:数据小太阳 更新时间:2023-10-29 06:41:22 25 4
gpt4 key购买 nike

我正在尝试使用回形针、aws-sdk gem 和 Amazon S3 创建图像 uploader 。我收到此错误:

Aws::Errors::MissingRegionError in ProjectsController#create. 
Missing region; use :region option or export region name to ENV['AWS_REGION']. using Oregon region.

projects_controller.rb

def create
@project = current_user.projects.new(project_params)
@project.save
respond_with(@project)
end

application.rb 文件

config.paperclip_defaults = {
storage: :s3,
s3_host_name: "s3-us-west-2.amazonaws.com",
s3_credentials: {
bucket: ENV['AWS_BUCKET'],
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
}
}

根据我了解的 S3 文档,我需要更改为 ENV['AWS_REGION']

config.paperclip_defaults = {
storage: :s3,
region: "ENV['AWS_REGION"],
s3_credentials: {
bucket: ENV['AWS_BUCKET'],
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
}
}

并将区域添加到我的 .env 文件

export AWS_BUCKET=realv1
export AWS_ACCESS_KEY_ID=<MY_ACCESS_KEY_ID_HERE>
export AWS_SECRET_ACCESS_KEY=<MY_ACCESS_KEY_HERE>
export AWS_REGION="'us-west-2'

我重新启动了服务器并重新测试,但仍然出现相同的错误。

更新

更新:

在 Rails 控制台中

2.0.0p247 :001 > ENV["AWS_REGION"]

=> "us-west-2"2.0.0p247 :002 >

最佳答案

错误源自 Paperclip gem。在您的 config.paperclip_defaults 中,您在本应使用 s3_region 时使用了 region。这是配置的外观:

config.paperclip_defaults = {
:storage => :s3,
:s3_region => ENV['AWS_REGION'],
:s3_credentials => {
:bucket => ENV['S3_BUCKET_NAME'],
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
}
}

关于ruby-on-rails - Rails4.1 : AWS errors missing region,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32224995/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com