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.

19 lines
631 B

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