【问题标题】:Amazon S3 path or to_file wont workAmazon S3 路径或 to_file 不起作用
【发布时间】:2026-01-21 02:40:01
【问题描述】:

大家好,我的模型中有以下代码

需要'RMagick'

类上传

has_attached_file :photo,
                  :styles => {
                    :thumb => ["100x100", :jpg],
                    :pagesize => ["500x400", :jpg],
                  },
                  :storage => :s3,
                      :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
                      :path => ":attachment/:id/:style.:extension",
                      :bucket => 'your_deck',
                  :default_style => :pagesize

attr_accessor :x1, :y1, :width, :height

def update_attributes(att)

  scaled_img = Magick::ImageList.new(self.photo.path)
  orig_img = Magick::ImageList.new(self.photo.path(:original))
  scale = orig_img.columns.to_f / scaled_img.columns

  args = [ att[:x1], att[:y1], att[:width], att[:height] ]
  args = args.collect { |a| a.to_i * scale }

  orig_img.crop!(*args)
  orig_img.write(self.photo.path(:original))

  self.photo.reprocess!
  self.save

  super(att)
end

结束

此代码可以离线工作,但是在使用 Amazon S3 的 Heroku 上它无法工作,我尝试使用 to_file 的代码,它也无法工作

我收到以下错误

无法将数组转换为字符串

【问题讨论】:

    标签: ruby-on-rails heroku paperclip


    【解决方案1】:

    我遇到了同样的问题,这是由于update 到回形针。我很惊讶 heroku 仍在使用这个 gem 版本,因为它肯定会影响到所有用户;我安装了以前的版本作为插件,很好。不要忘记从 .gems 文件中删除 gem 或在 gem 清单中指定以前的版本。

    【讨论】: