You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
682 B

  1. # frozen_string_literal: true
  2. require 'mime/types/columnar'
  3. module Paperclip
  4. class TypeCorrector < Paperclip::Processor
  5. def make
  6. return @file unless options[:format]
  7. target_extension = '.' + options[:format]
  8. extension = File.extname(attachment.instance_read(:file_name))
  9. return @file unless options[:style] == :original && target_extension && extension != target_extension
  10. attachment.instance_write(:content_type, options[:content_type] || attachment.instance_read(:content_type))
  11. attachment.instance_write(:file_name, File.basename(attachment.instance_read(:file_name), '.*') + target_extension)
  12. @file
  13. end
  14. end
  15. end