我刚刚从在本地存储通过 Carrierwave 上传的图像切换到通过我的 Rails 3.1 应用程序中的雾 gem 使用 Amazon s3。添加图像时,当我单击应用程序中的图像时,URL 提供了我的访问密钥和签名。这是一个示例 URL(XXX 将字符串替换为信息):
https://s3.amazonaws.com/bucketname/uploads/photo/image/2/IMG_4842.jpg?AWSAccessKeyId=XXX&Signature=XXX%3D&Expires=1332093418
这发生在开发(本地主机:3000)和我使用 heroku 进行生产时。这是我的上传者:
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
storage :fog
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
process :convert => :jpg
process :resize_to_limit => [640, 640]
version :thumb do
process :convert => :jpg
process :resize_to_fill => [280, 205]
end
version :avatar do
process :convert => :jpg
process :resize_to_fill => [120, 120]
end
end
还有我的 config/initializers/fog.rb :
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => 'XXX',
:aws_secret_access_key => 'XXX',
}
config.fog_directory = 'bucketname'
config.fog_public = false
end
任何人都知道如何确保此信息不可用?
更新:添加视图和控制器代码:来自部分用户/show.html.erb:
<% if @user.photos.any? %>
<% for photo in @user.photos %>
<li class="span4 hidey">
<div class="thumb_box">
<%=link_to(image_tag(photo.image_url(:thumb).to_s), photo.image_url.to_s,
:class=>"lb_test") %>
...
</div>
</li>
<% end %>
<% end %>
users_controller.rb:
def show
@user = User.find(params[:id])
end
更新:添加从 url 中删除访问密钥信息时得到的错误页面:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>47077D6EC13AD1D8</RequestId>
<HostId>+HTeODcWTqv3gbRIAwf+lI6sPzfNTegDXjT9SnMdqrYr7gLD1TD0qN+OgMLwA1JO
</HostId>
</Error>