gitlab-org--gitlab-foss/app/services/upload_service.rb

25 lines
603 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class UploadService
2018-07-11 08:52:48 -04:00
def initialize(model, file, uploader_class = FileUploader, **uploader_context)
@model, @file, @uploader_class, @uploader_context = model, file, uploader_class, uploader_context
end
def execute
return unless file && file.size <= max_attachment_size
uploader = uploader_class.new(model, nil, **uploader_context)
uploader.store!(file)
uploader
end
private
attr_reader :model, :file, :uploader_class, :uploader_context
def max_attachment_size
Gitlab::CurrentSettings.max_attachment_size.megabytes.to_i
end
end