【问题标题】:paperclip content type for xls and xlsxxls 和 xlsx 的回形针内容类型
【发布时间】:2016-03-28 11:53:59
【问题描述】:

纠结于回形针内容类型,需要上传 xls/xlsx 文件。

has_attached_file :sheet
validates_attachment_content_type :sheet, content_type: [
                                          'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
                                          'application/zip',
                                          'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
                                          'application/vnd.ms-excel',
                                          'application/xls',
                                          'application/xlsx',
                                          'application/octet-stream'
                                        ],
                                message: ' Only EXCEL files are allowed.' 

注意:从谷歌驱动器创建了一个工作表。

我尝试了以上内容类型,但每次都遇到相同的错误

输出

Command :: file -b --mime '/var/folders/zy/khy_wsfn7jbd40bsdps7qwqc0000gt/T/5a76e813d6a0a40548b91acc11557bd220160328-13642-1meqjap.xlsx'
   (0.2ms)  BEGIN
Command :: file -b --mime '/var/folders/zy/khy_wsfn7jbd40bsdps7qwqc0000gt/T/5a76e813d6a0a40548b91acc11557bd220160328-13642-114d8t6.xlsx'
   (0.3ms)  ROLLBACK
{:sheet_content_type=>[" Only EXCEL files are allowed."], :sheet=>[" Only EXCEL files are allowed."]}

【问题讨论】:

    标签: excel ruby-on-rails-4 paperclip paperclip-validation


    【解决方案1】:

    错过了路径; (

    通过使用修复它

    has_attached_file :sheet,
                    :path => ":rails_root/public/system/:attachment/:id/:filename"
    
    validates_attachment :sheet, presence: true,
                       content_type: { content_type: [
                         "application/vnd.ms-excel",
                         "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
                       ]
                       },
                       message: ' Only EXCEL files are allowed.'
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多