用神社保存PDF

时间:2018-04-11 22:38:29

标签: ruby-on-rails shrine

我试图用Shrine保存pdf文件。在靖国神社readme之后,我归咎于

my_model.image = File.open('my_pdf.pdf')

但这会引发错误:

Encoding::UndefinedConversionError: "\xFE" from ASCII-8BIT to UTF-8

我怎样才能完成这个?有一种方法可以用Shrine保存二进制文件吗?

以下是我使用的上传者:

class DocumentUploader < Shrine
  plugin :logging
  plugin :validation_helpers
  plugin :determine_mime_type, analyzer: :mimemagic
  plugin :data_uri

  Attacher.validate do
    validate_max_size 20*1024*1024, message: "is too large (max is 20 MB)"
    validate_mime_type_inclusion %w[
      image/jpeg
      image/gif
      image/bmp
      image/png
      image/tiff
      application/pdf
    ]
  end
end

0 个答案:

没有答案