I created a method in my model to validate the upload file type. But it won't work, and I assume it's because i am using Direct uploads.
Is it possible to validate the file type with direct uploads with active storage? and How can I?
I tried:
Model:
validate :correct_video_type
def correct_video_type
if video.attached? && video.content_type.in?(%w(video/mov video/mp4 video/avi video/mpeg))
errors.add(:video, "Must be video format")
elsif video.attached? == false
errors.add(:video, "Video must be attached")
end
end
View:
<%= form.file_field :video, class: "upload", direct_upload: true %>
And nothing becomes validated...
I also tried front end validation, but this didn't work:
<%= form.file_field :video, class: "upload", direct_upload: true, accept: 'video/mov, video/mpeg, video/mp4, video/avi' %>
None of these worked. Even if the front-end were to work, i would still want to validate it further on the backend.
How can I validate this?