Fix converted media being saved with original extension and mime type (#11130)

This commit is contained in:
Eugen Rochko
2019-06-20 10:52:36 +02:00
committed by GitHub
parent 7696f77245
commit 8f23726918
4 changed files with 26 additions and 4 deletions

View File

@ -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