Skip to content

Commit bc24451

Browse files
ClearlyClaireMage
authored andcommitted
Fix larger video files not being transcoded (mastodon#14306)
Since mastodon#14145, the `set_type_and_extension` has been moved from `before_post_process` to `before_file_post_process`, but while the former runs before all validations performed by Paperclip, the latter is dependent on the order validations and hooks are defined. In our case, this meant video files could be checked against the generic 10MB limit, causing validation failures, which, internally, make Paperclip skip post-processing, and thus, transcoding of the video file. The actual validation would then happen after the type is correctly set, so the large file would pass validation, but without being transcoded first. This commit moves the hook definition so that it is run before checking for the file size.
1 parent c14c98e commit bc24451

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

app/models/media_attachment.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ class MediaAttachment < ApplicationRecord
165165
processors: ->(f) { file_processors f },
166166
convert_options: GLOBAL_CONVERT_OPTIONS
167167

168+
before_file_post_process :set_type_and_extension
169+
before_file_post_process :check_video_dimensions
170+
168171
validates_attachment_content_type :file, content_type: IMAGE_MIME_TYPES + VIDEO_MIME_TYPES + AUDIO_MIME_TYPES
169172
validates_attachment_size :file, less_than: IMAGE_LIMIT, unless: :larger_media_format?
170173
validates_attachment_size :file, less_than: VIDEO_LIMIT, if: :larger_media_format?
@@ -258,9 +261,6 @@ def delay_processing_for_attachment?(attachment_name)
258261

259262
after_post_process :set_meta
260263

261-
before_file_post_process :set_type_and_extension
262-
before_file_post_process :check_video_dimensions
263-
264264
class << self
265265
def supported_mime_types
266266
IMAGE_MIME_TYPES + VIDEO_MIME_TYPES + AUDIO_MIME_TYPES

0 commit comments

Comments
 (0)