【问题标题】:Carrierwave pdf upload failed to manipulateCarrierwave pdf 上传操作失败
【发布时间】:2018-10-10 11:09:15
【问题描述】:

我正在使用 CarrierWave 在我的应用程序中上传文件。自 2018 年 10 月 6 日起,突然无法上传 pdf 文件,应用程序引发此错误:

Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: 
`identify /tmp/mini_magick20181010-10534-s5jchg.pdf` failed with error: 
identify: not authorized `/tmp/mini_magick20181010-10534-s5jchg.pdf' @ 
error/constitute.c/ReadImage/412. 

同样有很多问题,但没有一个答案能解决这个问题。我也尝试过使用 Rmagick,但没有运气。

下面是我的上传器设置

class AttachmentUploader < CarrierWave::Uploader::Base

  # Include RMagick or MiniMagick support:
  # include CarrierWave::RMagick
  include CarrierWave::MiniMagick

  # Choose what kind of storage to use for this uploader:
  #storage :file
  storage :fog

  # Override the directory where uploaded files will be stored.
  # This is a sensible default for uploaders that are meant to be mounted:
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  # Provide a default URL as a default if there hasn't been a file uploaded:
  def default_url
    "no-photo.png"
  end


  # Create different versions of your uploaded files:

  version :thumb do
    # crop to exactly 80px x 80px
    process :resize_to_fill => [80, 80]
  end

  version :web do
    # scale to be no larger than 800px x 500px
    process :resize_to_limit => [800, 500]
  end

  # Add a white list of extensions which are allowed to be uploaded.
  # For images you might use something like this:
  # def extension_white_list
  #   %w(jpg jpeg gif png)
  # end

  # Override the filename of the uploaded files:
  # Avoid using model.id or version_name here, see uploader/store.rb for details.
  # def filename
  #   "something.jpg" if original_filename
  # end

end

让我知道你的想法。

谢谢

【问题讨论】:

  • 不适用于 pdf,因为您的上传器的操纵器是专门为图像设计的,它们不能用于 pdf?
  • version :thumbversion :web 之后添加, :if =&gt; :image? ?
  • 是的,我同意我已经进行了这些更改,但我想知道以前是如何工作的。
  • 也许版本更新了,他们以前处理过这样的事情?不确定
  • 希望您正在使用 git 版本控制并且可以看到您的代码中可能发生了什么变化?你找到解决办法了吗?你可能不需要CarrierWave::MiniMagick 是否尝试将其注释掉?

标签: ruby-on-rails ruby ruby-on-rails-4 carrierwave rmagick


【解决方案1】:

这是由 2018 年 10 月发布的 ImageMagick 中的安全更新 (https://launchpad.net/ubuntu/+source/imagemagick/8:6.7.7.10-6ubuntu3.13) 引起的。

有一个非常简单的解决方法。见https://stackoverflow.com/a/52661288/935514

注意:你只需要改变&lt;policy domain="coder" rights="read|write" pattern="PDF" /&gt;这一行,你只需要重启web worker,而不是整个服务器。

【讨论】:

    猜你喜欢
    • 2016-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多