我使用paperclip和amazon s3上传文件。我没有文件上传的任何问题。但是,当我尝试打开该文件时,我遇到以下错误。由于我是初学者,请向我建议解决方案。 这是我的错误
PermanentRedirectThe bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.BCD25D22BDC4E922webtutorUbptlDdULmHVXgEPqp/JknHeGhsddn3zmw50a0GGRTCWMsEI/BTVHEK4SyeYrPIGwebtutor.s3.amazonaws.com
这是我的模特;
class Tutorial < ActiveRecord::Base
def self.search(search)
search_condition = "%" + search + "%"
find(:all, :conditions => ['tutorial_name ILIKE ? OR tutorial_discription ILIKE ?', search_condition, search_condition])
end
attr_accessible :tutorial_date_release, :tutorial_discription, :tutorial_name, :tutorial_path, :tutorial_teacher_name, :avatar, :CategoryID, :TutorialType
belongs_to :category
has_many :comments, dependent: :destroy #relationship between comments and tutorials (if u delete a tutorials all comments will be deleted)
scope :math, lambda{where(:CategoryID => 'Mathematics')}
scope :reading, lambda{where(:CategoryID => 'Reading')}
scope :writing, lambda{where(:CategoryID => 'Writing')}
validates_presence_of :tutorial_date_release
validates_presence_of :tutorial_discription
validates_presence_of :tutorial_name
#validates_presence_of :tutorial_teacher_name
###Paperclip
has_attached_file :avatar,:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",:path => ":attachment/:id.:extension",:bucket => 'webtutor'
#has_attached_file :avatar
validates_attachment_content_type :avatar, :content_type => /.*/
end
这是我的show.html.erb
<% @page_title = "User Menu" %>
<header>
<%= render 'access/navigation' %>
</header>
<br/>
<br />
<p> <b><center><font size="5"><%= @tutorial.tutorial_name %></font></center></b></p>
<p><center><iframe
src="<%= @tutorial.avatar %>" style="width:800px; height:600px;" frameborder="5"/></iframe>
</center> </p>
<a href="<%= @tutorial.avatar %>" download="<%= @tutorial.avatar %>" >You can download this too!</a>
<br />
<%= link_to 'Back', tutorials_path %>
<br />
<h2> Comments </h2>
<div id="comments">
<%= render :partial => @tutorial.comments.reverse %>
</div>
<%= form_for([@tutorial, Comment.new], remote: true) do |f| %>
<p>
<%= f.label :body, "New Comment" %><br />
<%= f.text_area :body,:cols => "40", :rows => "1" %>
</p>
<p><%= f.submit "Add Comment" %></p>
<% end %>
S3.yml文件
development:
bucket: XXX
access_key_id: xx
secret_access_key: XX
test:
bucket: XX
access_key_id: XX
secret_access_key: XX
production:
bucket: XX
access_key_id: XX
secret_access_key: XX
答案 0 :(得分:1)
首先,您需要从:bucket => 'webtutor'
调用中删除 has_attached_file
,因为它应该是您:s3_credentials
中已设置的s3.yml
的一部分。
此外,我建议您将 :url
选项传递给has_attached_file
。
定义has_attached_file如下:
has_attached_file :avatar,:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:path => ":attachment/:id.:extension",
:url => ":s3_domain_url"
根据 RDoc for Module: Paperclip::Storage::S3
但在某些情况下,路径不起作用,你需要使用 domain-style(:s3_domain_url)。这里的任何其他东西都会被视为 路径样式。
注意:此选项的值是字符串,而不是符号。对: &#34;:s3_domain_url&#34;错误:: s3_domain_url