rails paperclip验证内容类型

时间:2017-02-02 02:39:25

标签: ruby-on-rails amazon-s3 paperclip mime-types ruby-on-rails-5

我目前正在处理paperclip + s3文件上传工作。

我已经从随机博客中列出了所有可能的mime类型......但正如你所看到的,它真的很乱,完全不能重复使用。

清理这些的任何线索......?

我已经查看了在mime_types.rb文件中添加行但不知道如何使用它们。

请帮帮我

class Board < ActiveRecord::Base
  resourcify
  include Authority::Abilities

  belongs_to :consulting
  belongs_to :user

  has_many :comments, as: :commentable, dependent: :destroy

  has_attached_file :file
  validates_attachment_content_type :file, :content_type => %w(
                                                            audio/basic
                                                            video/msvideo, video/avi, video/x-msvideo
                                                            image/bmp
                                                            application/x-bzip2
                                                            text/css
                                                            application/xml-dtd
                                                            application/msword
                                                            application/vnd.openxmlformats-officedocument.wordprocessingml.document
                                                            application/vnd.openxmlformats-officedocument.wordprocessingml.template
                                                            application/ecmascript
                                                            application/octet-stream
                                                            image/gif
                                                            application/x-gzip
                                                            application/mac-binhex40
                                                            text/html
                                                            application/java-archive
                                                            image/jpeg
                                                            application/x-javascript
                                                            audio/x-midi
                                                            audio/mpeg
                                                            video/mpeg
                                                            audio/vorbis, application/ogg
                                                            application/pdf
                                                            application/x-perl
                                                            image/png
                                                            application/vnd.openxmlformats-officedocument.presentationml.template
                                                            application/vnd.openxmlformats-officedocument.presentationml.slideshow
                                                            application/vnd.ms-powerpointtd>
                                                            application/vnd.openxmlformats-officedocument.presentationml.presentation
                                                            application/postscript
                                                            video/quicktime
                                                            audio/x-pn-realaudio, audio/vnd.rn-realaudio
                                                            audio/x-pn-realaudio, audio/vnd.rn-realaudio
                                                            application/rdf, application/rdf+xml
                                                            application/rtf
                                                            text/sgml
                                                            application/x-stuffit
                                                            application/vnd.openxmlformats-officedocument.presentationml.slide
                                                            image/svg+xml
                                                            application/x-shockwave-flash
                                                            application/x-tar
                                                            application/x-tar
                                                            image/tiff
                                                            text/tab-separated-values
                                                            text/plain
                                                            audio/wav, audio/x-wav
                                                            application/vnd.ms-excel.addin.macroEnabled.12
                                                            application/vnd.ms-excel
                                                            application/vnd.ms-excel.sheet.binary.macroEnabled.12
                                                            application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
                                                            application/vnd.openxmlformats-officedocument.spreadsheetml.template
                                                            application/xml
                                                            application/zip, application/x-compressed-zip
                                                         )
  validates_with AttachmentSizeValidator, attributes: :file, less_than: 20.megabytes

end

谢谢你

0 个答案:

没有答案