Fix audio-only OGG and WebM files not being processed as such (#11151)
Also, because Chrome sends audio/mp3 instead of audio/mpeg as it's supposed to, we need to whitelist that mime type as well
This commit is contained in:
parent
6eb5241099
commit
b927bb3f07
2 changed files with 19 additions and 2 deletions
|
@ -10,10 +10,21 @@ module Attachmentable
|
|||
included do
|
||||
before_post_process :set_file_extensions
|
||||
before_post_process :check_image_dimensions
|
||||
before_post_process :set_file_content_type
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_file_content_type
|
||||
self.class.attachment_definitions.each_key do |attachment_name|
|
||||
attachment = send(attachment_name)
|
||||
|
||||
next if attachment.blank? || attachment.queued_for_write[:original].blank?
|
||||
|
||||
attachment.instance_write :content_type, calculated_content_type(attachment)
|
||||
end
|
||||
end
|
||||
|
||||
def set_file_extensions
|
||||
self.class.attachment_definitions.each_key do |attachment_name|
|
||||
attachment = send(attachment_name)
|
||||
|
@ -47,4 +58,10 @@ module Attachmentable
|
|||
|
||||
extension
|
||||
end
|
||||
|
||||
def calculated_content_type(attachment)
|
||||
Paperclip.run('file', '-b --mime :file', file: attachment.queued_for_write[:original].path).split(/[:;\s]+/).first.chomp
|
||||
rescue Terrapin::CommandLineError
|
||||
''
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue