Class: Gitlab::ImportExport::RemoteStreamUpload

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/import_export/remote_stream_upload.rb

Defined Under Namespace

Classes: ChunkStream, StreamError

Instance Method Summary collapse

Constructor Details

#initialize(download_url:, upload_url:, options: {}) ⇒ RemoteStreamUpload

Returns a new instance of RemoteStreamUpload.



12
13
14
15
16
17
# File 'lib/gitlab/import_export/remote_stream_upload.rb', line 12

def initialize(download_url:, upload_url:, options: {})
  @download_url = download_url
  @upload_url = upload_url
  @upload_method = options[:upload_method] || :post
  @upload_content_type = options[:upload_content_type] || 'application/gzip'
end

Instance Method Details

#executeObject



19
20
21
22
23
24
25
26
27
# File 'lib/gitlab/import_export/remote_stream_upload.rb', line 19

def execute
  receive_data(download_url) do |response, chunks|
    send_data(upload_url, response.content_length, chunks) do |response|
      if response.code != '200'
        raise StreamError.new("Invalid response code while uploading file. Code: #{response.code}", response.body)
      end
    end
  end
end