所以我允许使用Paperclip上传许多类型的文件(pdf,doc,docx,ppt,pptx,xls,xlsx和zip)。
到目前为止一切顺利,一切正常。 除了一件事。我注意到* .xls文件没有上传。
这是我的模型Document
class Document < ActiveRecord::Base
has_attached_file :file
validates_attachment_content_type :file,
content_type: [
"application/pdf",
"application/vnd.ms-excel",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"application/msword",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"application/vnd.ms-powerpoint",
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
"application/zip"]
end
我正在使用S3,这个问题发生在本地和生产(heroku)。我听说它可以链接到浏览器本身;但是,我测试了(在os x下)Chrome,Safari,Firefox和Opera没有成功。
当我尝试上传xls文件名this-is-a-test-file.xls
时的日志:
Started POST "/documents" for ::1 at 2016-08-26 01:41:54 +0200
Processing by DocumentsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"GdnkT1Iw8ajORrrSidpQ4Un4qlcN7qzZFk00j3fTTe0VpDO4ZhGQQG0ckO5DmrDzDdqzLw5SXI+O3p72zuP6qQ==", "document"=>{"file"=>#<ActionDispatch::Http::UploadedFile:0x007fdcc5479b78 @tempfile=#<Tempfile:/var/folders/gc/r_620xsx5hs44l70ftvwxpjr0000gn/T/RackMultipart20160826-79534-4kin0o.xls>, @original_filename="this-is-a-test-file.xls", @content_type="application/octet-stream", @headers="Content-Disposition: form-data; name=\"document[file]\"; filename=\"this-is-a-test-file.xls\"\r\nContent-Type: application/octet-stream\r\n">}, "commit"=>"upload file"}
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 1]]
Command :: file -b --mime '/var/folders/gc/r_620xsx5hs44l70ftvwxpjr0000gn/T/99ca719bb8fc2d3a1543726223f4d54520160826-79534-10bpmb.xls'
(0.2ms) BEGIN
Command :: file -b --mime '/var/folders/gc/r_620xsx5hs44l70ftvwxpjr0000gn/T/99ca719bb8fc2d3a1543726223f4d54520160826-79534-176ftj5.xls'
(0.2ms) ROLLBACK
Redirected to http://localhost:3000/documents
Completed 302 Found in 82ms (ActiveRecord: 0.8ms)
有什么想法吗? :)