summaryrefslogtreecommitdiff
path: root/app/services/upload_service.rb
blob: 76700dfcdeee4fc6a5cefb38cb965d39ae498f38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class UploadService
  include Gitlab::CurrentSettings

  def initialize(model, file, uploader_class = FileUploader)
    @model, @file, @uploader_class = model, file, uploader_class
  end

  def execute
    return nil unless @file && @file.size <= max_attachment_size

    uploader = @uploader_class.new(@model)
    uploader.store!(@file)

    uploader.to_h
  end

  private

  def max_attachment_size
    current_application_settings.max_attachment_size.megabytes.to_i
  end
end