从Amazon S3存储桶打开文件时出错

Pritesh

我正在使用回形针和亚马逊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
柯蒂·索拉特(Kirti Thorat)

首先,您需要通话中删除 :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:回形针::存储:: S3

但是在某些情况下,路径不起作用,您需要使用域样式(:s3_domain_url)。这里的任何其他内容都将被视为路径样式。

注意:此选项的值是字符串,而不是符号。正确:“:s3_domain_url”错误::s3_domain_url

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

将文件上传到Amazon S3存储桶时出错

来自分类Dev

无法替换Amazon S3存储桶中的文件

来自分类Dev

Amazon S3在版本存储桶中管理文件

来自分类Dev

尝试直接将文件上传到Amazon S3存储桶时请求失败

来自分类Dev

Amazon S3安全存储桶

来自分类Dev

Amazon S3存储桶的Favicon

来自分类Dev

Android Amazon S3存储桶

来自分类Dev

Android Amazon S3存储桶

来自分类Dev

创建Amazon s3存储桶时,是否可以设置自动写入存储桶的策略?

来自分类Dev

将“Azure Blob 存储”文件 URL 流式传输到 Amazon S3 存储桶

来自分类Dev

Amazon S3存储桶策略,允许用户写入存储桶,但仅限该存储桶

来自分类Dev

使用API在Amazon S3存储桶中创建文件夹/上传文件

来自分类Dev

删除位于Amazon S3上存储桶中的子文件夹中的文件

来自分类Dev

在 Laravel 中压缩和下载 Amazon S3 存储桶文件和文件夹

来自分类Dev

Amazon S3存储桶命名约定

来自分类Dev

从Amazon S3存储桶检索图像

来自分类Dev

Amazon S3存储桶返回403禁止访问

来自分类Dev

如何使用通配符搜索Amazon S3存储桶?

来自分类Dev

存储桶级别的Amazon S3安全URL

来自分类Dev

您如何全文搜索amazon s3存储桶?

来自分类Dev

子域指向Amazon S3存储桶

来自分类Dev

Amazon S3存储桶缓存清除

来自分类Dev

将Namecheap域与Amazon S3存储桶连接

来自分类Dev

Amazon S3存储桶策略阻止用户代理

来自分类Dev

Amazon S3中的最佳存储桶数

来自分类Dev

Amazon S3存储桶策略公共

来自分类Dev

Amazon S3存储桶命名约定

来自分类Dev

防止Amazon S3存储桶强制下载

来自分类Dev

在Amazon S3存储桶中安装MeteorJS