So I'm allow many types of file to be uploaded (pdf, doc, docx, ppt, pptx, xls, xlsx and zip) using Paperclip.
So far so good, everything works fine. Except one thing. I noticed that the *.xls file where not uploaded.
Here my model 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
I'm using S3 and this issue is happening in local and production (heroku). I kind of heard that it could be linked to the browser itself; however, I did test on (under os x) Chrome, Safari, Firefox and Opera without success.
Here the log when I try to upload a xls file name 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)
Any idea ? :)