开发者

How can I restrict Paperclip to only accept images?

开发者 https://www.devze.com 2023-02-04 16:36 出处:网络
How can I restrict Paperclip to only accept image开发者_如何学JAVAs? I\'m using Amazon S3 for storage if that\'s relevant. Thanks for reading.From https://makandracards.com/makandra/606-only-allow-pic

How can I restrict Paperclip to only accept image开发者_如何学JAVAs? I'm using Amazon S3 for storage if that's relevant. Thanks for reading.


From https://makandracards.com/makandra/606-only-allow-pictures-as-paperclip-attachments

validates_attachment_content_type :image, :content_type => /^image\/(jpg|jpeg|pjpeg|png|x-png|gif)$/, :message => 'file type is not allowed (only jpeg/png/gif images)'


Paperclip has validation methods like validates_attachment_presence, validates_attachment_content_type, and validates_attachment_size.

So all you need to do is pass mime types of images you'd like to have as attachments:

validates_attachment_content_type 'image/png', 'image/jpg'
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号