我试图用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