载波上传 - 图片或视频
Carrierwave upload - image or video
我发现 this link 解释了如果上传的不是视频,如何不制作缩略图。
但是之后我如何检查保存的文件是不是图像? (在我的例子中,我可以存储图像或视频),方法是在包含上传器的模型上调用一个方法?我是否需要 is_image?(new_file)
中的某种回调来在模型上设置字段?
我希望能够打电话给 @model.is_image?
或 @model.iI would bes_video?
或者甚至 case @model.type; when :video ; ...
我添加了一个回调以在包含上传器的模型上设置一个属性
# uploader/my_uploader.rb
...
def image?(new_file)
if new_file.content_type.include? 'image'
model.image = true
true
else
false
end
end
# models/my_model.rb (mongoid)
...
field :image, type: Boolean
mount_uploader MyUploader
# View
@my_model.image?
我发现 this link 解释了如果上传的不是视频,如何不制作缩略图。
但是之后我如何检查保存的文件是不是图像? (在我的例子中,我可以存储图像或视频),方法是在包含上传器的模型上调用一个方法?我是否需要 is_image?(new_file)
中的某种回调来在模型上设置字段?
我希望能够打电话给 @model.is_image?
或 @model.iI would bes_video?
或者甚至 case @model.type; when :video ; ...
我添加了一个回调以在包含上传器的模型上设置一个属性
# uploader/my_uploader.rb
...
def image?(new_file)
if new_file.content_type.include? 'image'
model.image = true
true
else
false
end
end
# models/my_model.rb (mongoid)
...
field :image, type: Boolean
mount_uploader MyUploader
# View
@my_model.image?