about summary refs log tree commit diff
path: root/app/models/media_attachment.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/media_attachment.rb')
-rw-r--r--app/models/media_attachment.rb10
1 files changed, 8 insertions, 2 deletions
diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb
index 85e82e12b..ec1808790 100644
--- a/app/models/media_attachment.rb
+++ b/app/models/media_attachment.rb
@@ -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