diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2019-06-20 10:52:36 +0200 |
---|---|---|
committer | multiple creatures <dev@multiple-creature.party> | 2020-02-21 03:42:05 -0600 |
commit | 2dacf79bcc58094b58f1689189ce130fb34b2c8f (patch) | |
tree | f39a9740405d1738ae06d319699c9910bf1b37ac /lib | |
parent | 480a83e843b92cc1fa4378b576bfd173024f3f8c (diff) |
port tootsuite#11130 to monsterfork: Fix converted media being saved with original extension and mime type
Diffstat (limited to 'lib')
-rw-r--r-- | lib/paperclip/type_corrector.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/paperclip/type_corrector.rb b/lib/paperclip/type_corrector.rb new file mode 100644 index 000000000..0b0c10a56 --- /dev/null +++ b/lib/paperclip/type_corrector.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require 'mime/types/columnar' + +module Paperclip + class TypeCorrector < Paperclip::Processor + def make + target_extension = options[:format] + extension = File.extname(attachment.instance.file_file_name) + + return @file unless options[:style] == :original && target_extension && extension != target_extension + + attachment.instance.file_content_type = options[:content_type] || attachment.instance.file_content_type + attachment.instance.file_file_name = File.basename(attachment.instance.file_file_name, '.*') + '.' + target_extension + + @file + end + end +end |