我有一个表单字段,用户可以在其中上传图像或文档(pdf、word、excel 等)。如何告诉 Shrine 上传者根据文件类型处理上传的文件。
class FileUploader < Shrine
plugin :processing
plugin :versions
plugin :delete_raw
plugin :validation_helpers
if File_is_image # <------ what to write here?
# do image processing
process(:store) do |io, context|
original = io.download
pipeline = ImageProcessing::MiniMagick.source(original)
size_800 = pipeline.resize_to_limit!(800, 800)
size_300 = pipeline.resize_to_limit!(300, 300)
original.close!
{ original: io, large: size_800, small: size_300 }
end
else
#do non image file processing
end
end
还是有更好的方法来做到这一点?