How to validate file content type to pdf, word, excel, and plain text for paperclip?

后端 未结 3 1778
醉话见心
醉话见心 2021-02-05 07:44

In my model:

 has_attached_file :uploaded_file,  
                      :url => \"/policy_documents/get/:id\",  
                      :path => \"/public/p         


        
3条回答
  •  渐次进展
    2021-02-05 08:44

    This is actually dependent on your servers 'file' command. What that command returns to you is what you need to be accepting in the paperclip validations.

    For example my Debian server returns "application/msword" for an xls file. And for an xlsx file it gives "application/zip".

    I currently have these to accept xls and xlsx files.

    validates_attachment_content_type :file, :content_type => %w(application/zip application/msword application/vnd.ms-office application/vnd.ms-excel application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
    

提交回复
热议问题