轨道上的红宝石 - S3, 雾, 费加罗, 载波: Excon::错误::禁止 (预期(200) <=> 实际(403 禁止)



我使用Carrierwave/Fog/S3与Figaro上传图片的yelp风格的网站。

整个站点在局部运行得很好,没有问题。在heroku上,它也工作得很好,直到我创建一个带有图像的新餐厅或尝试更新现有餐厅的图像,然后我在日志中得到这个:

 Excon::Errors::Forbidden (Expected(200) <=> Actual(403 Forbidden)  

这里是我的image_uploader.rb:

# encoding: utf-8
class ImageUploader < CarrierWave::Uploader::Base
  # Include RMagick or MiniMagick support:
  # include CarrierWave::RMagick
  include CarrierWave::MiniMagick
  # Choose what kind of storage to use for this uploader:
  if Rails.env.production?
    storage :fog
  else
    storage :file
  end
  # Override the directory where uploaded files will be stored.
  # This is a sensible default for uploaders that are meant to be mounted:
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end
  # Provide a default URL as a default if there hasn't been a file uploaded:
  # def default_url
  #   # For Rails 3.1+ asset pipeline compatibility:
  #   # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
  #
  #   "/images/fallback/" + [version_name, "default.png"].compact.join('_')
  # end
  # Process files as they are uploaded:
  process :resize_to_fit => [200, 300]
  #
  # def scale(width, height)
  #   # do something
  # end
  # Create different versions of your uploaded files:
  # version :thumb do
  #   process :resize_to_fit => [50, 50]
  # end
  # Add a white list of extensions which are allowed to be uploaded.
  # For images you might use something like this:
  # def extension_white_list
  #   %w(jpg jpeg gif png)
  # end
  # Override the filename of the uploaded files:
  # Avoid using model.id or version_name here, see uploader/store.rb for details.
  # def filename
  #   "something.jpg" if original_filename
  # end
  end
这是我的_form.html。在更新和新文件中呈现的动词:
<%= form_for(@restaurant, :html => {multipart: true}) do |f| %>
  <% if @restaurant.errors.any? %>
    <div id="error_explanation" class= "alert alert-danger alert-dismissable">
    <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
      <h4><%= pluralize(@restaurant.errors.count, "error") %> prohibited this restaurant from being saved:</h4>
      <ul>
      <% @restaurant.errors.full_messages.each do |message| %>
        <li><%= message %></li>
      <% end %>
      </ul>
    </div>
  <% end %>
 <div class="form-group">
    <%= f.label :name %><br>
    <%= f.text_field :name, class: "form-control", placeholder: "Panera Bread" %>
  </div>
  <div class="form-group">
    <%= f.label :address %><br>
    <%= f.text_field :address, class: "form-control", placeholder: "201 Brookline Avenue, Boston, MA 02215" %>
  </div>
  <div class="form-group">
    <%= f.label :phone %><br>
    <%= f.text_field :phone, class: "form-control", placeholder: "(617) 247-0174" %>
  </div>
  <div class="form-group">
    <%= f.label :website %><br>
    <%= f.text_field :website, class: "form-control", placeholder: "http://www.panerabread.com/" %>
  </div>
  <div class="form-group">
    <%= f.label :image %><br>
    <%= f.file_field :image, class: "form-control" %>
  </div>
  <div class="actions">
    <%= f.submit class: "btn btn-primary" %>
  </div>
<% end %>

我已经检查了钥匙,以确保它们是正确的。我为我的密钥添加了管理员访问策略(根据这个问题和这个问题)。我已经检查过权限了,都没问题。

到目前为止,睡觉还没有起作用(根据这个问题)

任何想法?

提前感谢!!

我可能离得很远,但请确保运行"heroku run rake db:migrate"以使数据库迁移到生产环境中,然后确保运行"heroku restart"。我不确定这将是你的问题的答案,但"英雄重启"帮助我挣扎了很长一段时间后。

我可以看到从AWS获得403的两个潜在原因:

  1. AWS没有正确设置权限(但你已经检查过了,你可以从你的机器上传图像,所以这种情况不太可能发生)
  2. 你从heroku实例传递给AWS的数据是错误的。

您是否可以附加一个文件,其中设置了S3桶的名称和密钥?您是否尝试运行Rails控制台并打印出配置的值?(您可以运行heroku run bash,然后连接到heroku dyno bundle exec rails console,然后,瞧,您可以访问您的生产服务器)。

你还写道,有时上传图片工作,但不是当创建一个新的餐厅或更新现有的一个。这些情况是什么?看看是什么让他们如此不同(以及在heroku上工作)可能会很有趣?

相关内容