2

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 ? :)

doem
  • 108
  • 5
  • I also tried to add `Mime::Type.register "application/vnd.ms-excel", :xls, [], %w(xls)` in `mime.types.rb` however it still doesn't work. – doem Aug 25 '16 at 23:54
  • can you try to add all the mime type listed here: http://stackoverflow.com/questions/974079/setting-mime-type-for-excel-document in your validate_attachment_content_type method. – Typpex Aug 26 '16 at 04:18
  • @Typpex that's what I did but did not work. – doem Aug 26 '16 at 22:14

0 Answers0