Video isn't of allowed type (allowed types: video/mp4), Shrine, Rails

拟墨画扇 提交于 2019-12-24 09:58:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!