【问题标题】:Refinerycms on Heroku not working with AmazonS3 bucketHeroku 上的 Refinerycms 无法使用 AmazonS3 存储桶
【发布时间】:2013-11-07 11:57:52
【问题描述】:

我尝试设置 Amazon S3 支持,以使用refinerycms 将图像存储在云中。

我在https://console.aws.amazon.com/s3/创建了存储桶

我将它命名为应用程序“bee-barcelona”,它说它在美国标准地区

~/config/initializers/refinery/images.rb 中我输入了所有数据(其中 'xxx? 代表我输入的实际键:

# Configure S3 (you can also use ENV for this)
# The s3_backend setting by default defers to the core setting for this but can be set just for images.
config.s3_backend = Refinery::Core.s3_backend
config.s3_bucket_name = ENV['bee-barcelona']
config.s3_access_key_id = ENV['xxx']
config.s3_secret_access_key = ENV['xxx']
config.s3_region = ENV['xxx']

然后我将更改应用到heroku:

heroku config:add S3_KEY=xxx S3_SECRET=xxx S3_BUCKET=bee-barcelona S3_REGION=us-standard

但是,当我尝试上传时,在应用程序中我只得到:“抱歉,出了点问题”。

我错过了什么?

【问题讨论】:

  • 你的日志说问题是什么? heroku logs.
  • 类似:vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:138:in service' 2013-11-07T12:41:34.741812+00:00 app[web.1]: Completed 500 Internal Server Error in 649.0ms 2013-11-07T12:41:34.740641+00:00 app[web.1]: vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:295:in block in start_thread' 2013-11-07T12:41 :34.740641+00:00 应用[web.1]: 2013-11-07T12:41:34.740641+00:00 应用[web.1]: 2013-11-07T12:41:34.741812+00:00 应用[web.1] 1]: Refinery::Admin::ImagesController#create as HTML 处理
  • 和:参数:{"utf8"=>"✓", "authenticity_token"=>"+UXRXJ13sDHK+T/put7sEWzEPoy/sGddfUxY+dgMkRE=", "image"=>{"image" =>[#<:http::uploadedfile:0x007f96681f7e20 form-data name='\"image[' image filename='\"Bee_Barcelona.jpg\"\r\nContent-Type:'>>] }, "wymeditor"=>"", "modal"=>"true", "dialog"=>"true", "app_dialog"=>"true", "field"=>"", "update_image"=> "", "缩略图"=>"", "回调"=>"", ...
  • 作为建议,您可能应该使用以下说明安装unicorn gem:devcenter.heroku.com/articles/rails-unicorn
  • 另外,除非您能从日志中获得更具体的错误信息,否则没有人能提供太多帮助。 (抱歉,不知道具体建议什么来解决这个问题。也许其他人会知道...)

标签: ruby-on-rails heroku amazon-web-services amazon-s3 refinerycms


【解决方案1】:

多么可悲的错误。在我跑了 10 公里之前,我没有考虑过这个选择……

我将应用设置为“养蜂” 我在亚马逊上的存储桶被命名为“bee-barcelona”

我确实在应用程序中注册了正确的存储桶。仍然炼油厂试图继续去另一个人的桶,命名为“养蜂”。有了我的密钥,我的文件就不会在那里结束。

我创建了一个新应用程序和一个新存储桶,所有这些都具有疯狂的名称,但是!它们在 AmazonS3 和 GIT 上是一样的!!!

不,它就像一个魅力。

多么罕见的情况……

【讨论】:

    【解决方案2】:

    我的做法是这样的:

    • 在区域 US-STANDARD 中创建存储桶!!!!!!!!!!!!
    • 你看到了吗?美国标准,不是俄勒冈州,不是其他任何地方。

    • 将宝石添加到 Gemfile

      gem "fog"
      gem "unf"
      gem "dragonfly-s3_data_store"
      
    • 在 config/application.rb 中

      config.assets.initialize_on_precompile = true
      
    • 在 config/environments/production.rb 中

      Refinery::Core.config.s3_backend = true
      
    • 在 config/environments/development.rb 中

      Refinery::Core.config.s3_backend = false
      
    • 为 heroku(生产)配置 S3 和用于开发的本地存储。在 config/initializers/refinery/core.rb

      if Rails.env.production?
        config.s3_backend = true
      else
        config.s3_backend = false
      end
      config.s3_bucket_name = ENV['S3_BUCKET']
      config.s3_region = ENV['S3_REGION']
      config.s3_access_key_id = ENV['S3_ACCESS_KEY']
      config.s3_secret_access_key = ENV['S3_SECRET_KEY']
      
    • 向heroku添加变量:

      heroku config:add S3_ACCESS_KEY=xxxxxx S3_SECRET_KEY=xxxxxx S3_BUCKET=bucket-name-here S3_REGION=us-east-1
      

    我遇到了很多问题,因为我在 S3_REGION=us-standard 之前遇到过。这是错误的。如图所示设置您的 US-Standard 存储桶:

    S3_REGION=us-east-1

    这对我来说在 Rails 4.2.1 和炼油厂 3.0.0 上完美运行。此外,请确保您对变量使用完全相同的名称。有时它会说 S3_KEY 而不是 S3_ACCESS_KEY 或 S3_SECRET 而不是 S3_SECRET_KEY。只需确保您的文件和 Heroku 变量中有相同的变量即可。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 2021-07-03
      • 1970-01-01
      • 2015-02-23
      • 2021-04-26
      • 2017-08-17
      相关资源
      最近更新 更多