使用mime-types
gems如何获取所有视频mime类型的数组?
答案 0 :(得分:1)
As the source shows,[]
采用正则表达式,因此您可以尝试:
videos = MIME::Types[/^video/]
或者,如果你已经加载了它,你可以访问Rack的列表:
Rack::Mime::MIME_TYPES.select{|(k,v)| v.start_with? "video" }
答案 1 :(得分:1)
您可以使用以下代码执行此操作:
require 'mime/types'
puts MIME::Types[/^video/, :complete => true]
输出:
video/3gpp
video/3gpp2
video/x-dl
video/dl
video/x-dv
video/x-fli
video/x-flv
video/x-gl
....
答案 2 :(得分:1)
video_types = []
MIME::Types[/^video/].map{|x| video_types << x.to_s }
或只是
MIME::Types[/^video/].map{|type| type.to_s }