我正在使用回形针和亚马逊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
首先,您需要从通话中删除 :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"
但是在某些情况下,路径不起作用,您需要使用域样式(:s3_domain_url)。这里的任何其他内容都将被视为路径样式。
注意:此选项的值是字符串,而不是符号。正确:“:s3_domain_url”错误::s3_domain_url
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句