如果用户尝试在 Ruby on Rails 应用程序中上传加密文件,我想给出验证错误消息。我正在使用神社宝石进行附件。我怎么能做到 - 有什么想法吗?
我正在使用:Rails 5.1.6,ruby 2.4.2p198,神社 2.9.0。
这是我的初始化程序
require 'shrine'
Shrine.plugin :activerecord
Shrine.plugin :cached_attachment_data # for forms
Shrine.plugin :determine_mime_type
Shrine.plugin :backgrounding
Shrine.plugin :delete_promoted
Shrine::Attacher.promote { |data| PromoteJob.perform_async(data) }
Shrine::Attacher.delete { |data| DeleteJob.perform_async(data) }
这个上传者
class DocumentUploader < Shrine
plugin :validation_helpers
plugin :pretty_location
plugin :processing
plugin :versions
process(:store) do |io, context|
original = io.download
out_file = Tempfile.new(["pdfsigned~", '.pdf'])
SignPdf.sign_pdf!(original, io.original_filename, out_file,
context[:record], context[:record].creator_company, :uploaded, {} , false)
{ original: io, stamped: out_file }
end
Attacher.validate do
validate_mime_type_inclusion ['application/pdf']
end
结尾
当我创建文档时。它不检查并接受加密文件