Skip to content

Commit

Permalink
Merge pull request #2447 from anthonypenner/master
Browse files Browse the repository at this point in the history
Add mime type detection for MS Office files
  • Loading branch information
mshibuya committed Oct 3, 2020
2 parents d41ad71 + 37af967 commit 2a0fefc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/carrierwave/sanitized_file.rb
Expand Up @@ -2,6 +2,7 @@
require 'active_support/core_ext/string/multibyte'
require 'mini_mime'
require 'mimemagic'
require 'mimemagic/overlay'

module CarrierWave

Expand Down
Binary file added spec/fixtures/resume.docx
Binary file not shown.
Binary file added spec/fixtures/slidedeck.pptx
Binary file not shown.
20 changes: 20 additions & 0 deletions spec/sanitized_file_spec.rb
Expand Up @@ -195,6 +195,26 @@
expect(sanitized_file.content_type).to eq("application/msword")
end

it "handles Mime::Type of docx" do
file = File.open(file_path('resume.docx'))

sanitized_file = CarrierWave::SanitizedFile.new(file)
allow(sanitized_file).to receive(:file).and_return(file)

expect { sanitized_file.content_type }.not_to raise_error
expect(sanitized_file.content_type).to eq("application/vnd.openxmlformats-officedocument.wordprocessingml.document")
end

it "handles Mime::Type of pptx" do
file = File.open(file_path('slidedeck.pptx'))

sanitized_file = CarrierWave::SanitizedFile.new(file)
allow(sanitized_file).to receive(:file).and_return(file)

expect { sanitized_file.content_type }.not_to raise_error
expect(sanitized_file.content_type).to eq("application/vnd.openxmlformats-officedocument.presentationml.presentation")
end

it "reads content type from path if missing" do
sanitized_file = CarrierWave::SanitizedFile.new("llama.jpg")

Expand Down

0 comments on commit 2a0fefc

Please sign in to comment.