debian-mirror-gitlab/app/services/upload_service.rb

21 lines
439 B
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
class UploadService
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
2018-03-17 18:26:18 +05:30
Gitlab::CurrentSettings.max_attachment_size.megabytes.to_i
2017-08-17 22:00:37 +05:30
end
end