我正在尝试用 Shrine 保存 pdf 文件。按照 Shrine自述文件,我正在归因
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