问题
I'm trying to validate my videos to only allow .mp4 videos to be uploaded. I'm using Shrine to do this. Videos upload no problem without validations, but if I add the validation code the error displays: Video isn't of allowed type (allowed types: video/mp4)
Here is my code:
video_uploader.rb
require "streamio-ffmpeg"
class VideoUploader < Shrine
plugin :processing
plugin :versions
plugin :determine_mime_type
plugin :cached_attachment_data
plugin :remove_attachment
plugin :add_metadata
add_metadata do |io|
video = FFMPEG::Movie.new(io.path)
{ "duration" => video.duration}
end
metadata_method :duration
Attacher.validate do
validate_max_size 200.megabyte, message: "is too large (max is 1 MB)"
validate_mime_type_inclusion ['video/mp4']
end
end
The video I'm trying to upload is definitely a .mp4 and I have this exact validation working in my image_uploader.rb
file, so I'm not sure why it isn't working with my video_uploader.rb
. Any ideas?
来源:https://stackoverflow.com/questions/51074008/video-isnt-of-allowed-type-allowed-types-video-mp4-shrine-rails