回形针:无法附加XLS(但DOC可以工作) [英] Paperclip: Cannot attach XLS (But DOC works)
本文介绍了回形针:无法附加XLS(但DOC可以工作)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法附加XLS文件,但DOC可以工作:
I cannot attach a XLS file, but DOC works:
附件文件的内容类型无效
附件文件无效
Attachments file content type is invalid
Attachments file is invalid
这是日志:
Parameters: ... "files"=>[#<ActionDispatch::Http::UploadedFile:0x0000000daf7730 @tempfile=#<Tempfile:C:/Users/Chloe/AppData/Local/Temp/RackMultipart20170511-47156-ym774u.xls>, @original_filename="Chocolate_Store1.xls", @content_type="application/vnd.ms-excel", @headers="Content-Disposition: form-data; name=\"deal[files][]\"; filename=\"Chocolate_Store1.xls\"\r\nContent-Type: application/vnd.ms-excel\r\n">],
...
Command :: file -b --mime "C:/Users/Chloe/AppData/Local/Temp/1f1fb4d71efc0bd245abd7b5b9aa661220170511-47156-1rqzd0q.xls"
(1.0ms) ROLLBACK
Rendering deals/edit.html.erb within layouts/application
当我测试类型时:
>file -b --mime "C:/Users/Chloe/AppData/Local/Temp/1f1fb4d71efc0bd245abd7b5b9aa661220170511-47156-1rqzd0q.xls"
application/vnd.ms-office; charset=binary
我的接受列表中有此类型:
I have this type in my accept list:
class Attachment < ApplicationRecord
has_attached_file :file
validates_attachment_content_type :file, content_type: [
"application/pdf", "application/msword",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"application/vnd.oasis.opendocument.text",
"application/vnd.ms-excel",
"application/vnd.ms-office",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"application/vnd.oasis.opendocument.spreadsheet"
]
end
Rails 5.0.2,Paperclip 5.1.0,File 5.04(DevKit)
Rails 5.0.2, Paperclip 5.1.0, File 5.04 (DevKit)
我注意到DevKit file
与Cygwin file
不同.不确定是否相关:
I noticed DevKit file
differs from Cygwin file
. Not sure if relevant:
>file -b --mime "C:/Users/Chloe/AppData/Local/Temp/1f1fb4d71efc0bd245abd7b5b9aa661220170515-54920-1e2bk5s.xls"
application/vnd.ms-office; charset=binary
$ file -b --mime "C:/Users/Chloe/AppData/Local/Temp/1f1fb4d71efc0bd245abd7b5b9aa661220170515-54920-1e2bk5s.xls"
application/vnd.ms-excel; charset=binary
推荐答案
我切换为使用
validates_attachment_file_name :file, matches: [/\.pdf$/, /\.docx?$/, /\.xlsx?$/, /\.odt$/, /\.ods$/]
这篇关于回形针:无法附加XLS(但DOC可以工作)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文