0
0
Fork 0

Fix #1642, fix #1912 - Dictate content-type file extension (#2078)

* Fix #1642, fix #1912 - Previous change (#1718) did not modify how original file was saved on upload

* Fix for when file is missing
This commit is contained in:
Eugen 2017-04-18 23:15:44 +02:00 committed by GitHub
parent 6bd1019235
commit e09ab2c0bd
3 changed files with 29 additions and 5 deletions

View file

@ -50,7 +50,7 @@ class MediaAttachment < ApplicationRecord
end
before_create :set_shortcode
before_post_process :set_type
before_post_process :set_type_and_extension
class << self
private
@ -103,7 +103,13 @@ class MediaAttachment < ApplicationRecord
end
end
def set_type
def set_type_and_extension
self.type = VIDEO_MIME_TYPES.include?(file_content_type) ? :video : :image
unless file.blank?
extension = Paperclip::Interpolations.content_type_extension(file, :original)
basename = Paperclip::Interpolations.basename(file, :original)
file.instance_write :file_name, [basename, extension].delete_if(&:empty?).join('.')
end
end
end