回形针+ S3 =>网址的一部分丢失了

时间:2016-02-11 10:45:05

标签: ruby-on-rails ruby-on-rails-4 amazon-s3

使用API​​,允许使用回形针上传图片。一切正常(图片可以保存在S3上)但我无法在我的JSON中显示正确的网址图片。

型号:

class Category < ActiveRecord::Base

  has_attached_file :picture,
    styles: { medium: "300x300>", thumb: "100x100>" },
    default_url: ":s3_eu_url"

    ...  some validations and accessors

end

序列化程序:

class CategorySerializer < ActiveModel::Serializer
  attributes :id, :title, :picture
end

Production.rb:

config.paperclip_defaults = {
  :storage => :s3,
  :s3_region => ENV['AWS_REGION'],
  :url => ':s3_domain_url',
  :s3_host_name => 's3-eu-west-1.amazonaws.com',
  :path => ':class/:attachment/:id_partition/:style/:filename',
  :s3_credentials => {
    :bucket => ENV['S3_BUCKET'],
    :access_key_id => ENV['S3_ACCESS_KEY'],
    :secret_access_key => ENV['S3_SECRET_KEY']
  }
}

回形针初始化程序:

if Rails.env.production?
  Paperclip.interpolates(:s3_eu_url) do |att, style|
    "#{att.s3_protocol}://#{att.bucket_name}.s3-eu-west-1.amazonaws.com/#{att.path(style)}"
  end
end

运行curl做一个帖子,我得到了(正确的url正在运行):

"http://wetal-assets-bucket.s3-eu-west-1.amazonaws.com/categories/pictures/000/000/397/original/elec.jpeg?1455186040"

我的JSON中显示的网址:

"http://wetal-assets-bucket.s3-eu-west-1.amazonaws.com/"

图片的路径丢失了,我无法找到显示它的方法。 即使我创建了一种方法来重新定义&#34;:picture&#34;在序列化器中为了返回&#34; object.picture.url&#34; ...仍然是相同的结果。

有什么建议吗?

0 个答案:

没有答案