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