Class: UploadService

Inherits:
Object
  • Object
show all
Defined in:
app/services/upload_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, file, uploader_class = FileUploader, **uploader_context) ⇒ UploadService

Returns a new instance of UploadService.


7
8
9
10
11
12
# File 'app/services/upload_service.rb', line 7

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

Instance Attribute Details

#override_max_attachment_sizeObject

Temporarily introduced for upload API: gitlab.com/gitlab-org/gitlab/-/issues/325788


5
6
7
# File 'app/services/upload_service.rb', line 5

def override_max_attachment_size
  @override_max_attachment_size
end

Instance Method Details

#executeObject


14
15
16
17
18
19
20
21
# File 'app/services/upload_service.rb', line 14

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

  uploader = uploader_class.new(model, nil, **uploader_context)
  uploader.store!(file)

  uploader
end