Add video storing into image uploader

Hello

Is it possible to save videos and images with one uploader?

Currently, I have an image uploader and have to modify it for videos too.

require 'image_processing/mini_magick'

class FeedbackPhotoUploader < Shrine
  include ImageProcessing::MiniMagick

  ALLOWED_TYPES = %w[image/jpeg image/png image/gif]
  MAX_SIZE      = (30 * 1024 * 1024)

  plugin :upload_endpoint, max_size: MAX_SIZE
  plugin :add_metadata

  plugin :processing
  plugin :delete_promoted
  plugin :versions

  plugin :determine_mime_type
  plugin :store_dimensions, analyzer: :mini_magick
  plugin :validation_helpers

  plugin :remove_attachment
  plugin :pretty_location

  Attacher.validate do
    validate_max_size MAX_SIZE
    if validate_mime_type_inclusion(ALLOWED_TYPES)
      validate_max_width 6000
      validate_max_height 6000
    end
  end

  process(:store) do |io, context|
    versions = { original: io }
    record   = context[:record]
    io.download do |original|
      pipeline = ImageProcessing::MiniMagick.source(original)

      versions[:big] = pipeline.resize_to_fit!(960 , 600)
      versions[:thumb]  = pipeline.resize_to_fit!(300, 167)
    end
    versions
  rescue StandardError => e
    AppLogger.logger.error "#{self.class} processing error: #{e.message}"
    AppLogger.logger.info e.backtrace.inspect
  end
end
#shrine version
shrine 2.19.4

It would be great to save a video preview as an image for using it later as

@user.image.big

Yes, it should be possible. Most of Shrine plugins are designed to support storing multiple types of files using the same uploader. If some lack necessary flexibility, I would definitely be open to improving them.

Yes, we are doing it with some custom logic in the uploader

class AttachmentUploader < Shrine

  IMAGE_TYPES = %w[
    image/jpeg
    image/png
    image/gif
    image/webp
    image/tiff
    image/bmp
    image/x-ms-bmp
  ].freeze
  VIDEO_TYPES = %w[
    video/mp4
    video/quicktime
    video/3gpp
  ].freeze
  Attacher.validate do
    validate_max_size 100.megabytes, message: 'is too large (max size is 100MB)'
    validate_mime_type (IMAGE_TYPES + VIDEO_TYPES)
  end

  Attacher.derivatives do |original|
    case file.mime_type
    when *IMAGE_TYPES
      process_derivatives(:thumb, original)
    when *VIDEO_TYPES
      {}
    end
  end

We process derivatives for image types, but simply store the original file, i.e. no derivatives for video types.