Carrierwave pdf上传失败

时间:2018-10-10 11:09:15

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

我正在使用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

让我知道你的想法。

谢谢

1 个答案:

答案 0 :(得分:0)

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

有一个非常简单的修复程序。参见https://stackoverflow.com/a/52661288/935514

注意:您只需要更改<policy domain="coder" rights="read|write" pattern="PDF" />行,并且只需要重新启动Web Worker,而不是整个服务器。