【发布时间】:2016-12-17 17:10:51
【问题描述】:
我最近按照教程创建了我的 Heroku here,将图像直接上传到我的 Amazon S3 存储桶。
当我上传文件时,它已成功发送到我的 S3 存储桶,但是当我尝试保存图像时出现以下错误
Paperclip::AdapterRegistry::NoHandlerError at /photos
No handler found for "//mys3bucket.s3.amazonaws.com/uploads/3452345aef45845blabla/the file name.fileExtension"
这是我认为的表格:
<%= bootstrap_form_for @photo, html: { multipart: true, class: 'directUpload', data: { 'form-data' => (@s3_direct_post.fields), 'url' => @s3_direct_post.url, 'host' => URI.parse(@s3_direct_post.url).host } } do |f| %>
<p>
<%= f.text_field :title %>
</p>
<p>
<%= f.file_field :image %>
</p>
<%= f.submit 'Upload', class: 'btn btn-success' %>
<% end %>
这是我在控制器中的创建方法:
def create
if can? :create, Photo
@photo = Photo.new(photo_params)
if @photo.save
redirect_to photos_path
else
render 'new'
end
else
redirect_to root_path
end
end
private
def photo_params
params.require(:photo).permit(:image, :title)
end
def set_s3_direct_post
@s3_direct_post = S3_BUCKET.presigned_post(key: "uploads/#{SecureRandom.uuid}/${filename}", success_action_status: '201', acl: 'public-read')
end
这是我的模型:
class Photo < ActiveRecord::Base
has_attached_file :image
belongs_to :article
validates :title, presence: true
validates :image,
attachment_content_type: { content_type: /\Aimage\/.*\Z/ },
attachment_size: { less_than: 5.megabytes }
end
这是我的全部repository
我知道出于某种原因 Paperclip 不知道如何处理 URL,但我不知道如何解决这个问题。我尝试在我的数据库中的照片表中添加一个新列,并将 URL 保存到该列。当然,这非常有效,因为没有涉及回形针。任何帮助将不胜感激。
【问题讨论】:
标签: ruby-on-rails-4 activerecord heroku amazon-s3 paperclip