我正在使用 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.erb:
<%= 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">×</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 %>
我检查了钥匙以确保它们是正确的。我向我的密钥添加了管理员访问策略(根据这个问题和这个问题)。我检查了权限,它们都很好。
到目前为止,睡在上面还没有奏效(根据这个问题。)
有任何想法吗?
提前致谢!!