Class: S3Streamer::Upstream

Inherits:
Object
  • Object
show all
Defined in:
lib/s3_streamer/upstream.rb

Instance Method Summary collapse

Constructor Details

#initialize(client, bucket, destination_file) ⇒ Upstream

Returns a new instance of Upstream.



3
4
5
6
7
8
9
10
# File 'lib/s3_streamer/upstream.rb', line 3

def initialize(client, bucket, destination_file)
  @client = client
  @bucket = bucket
  @destination_file = destination_file
  @parts = []
  @part_number = 1
  @upload_id = create
end

Instance Method Details

#completeObject



24
25
26
27
28
29
# File 'lib/s3_streamer/upstream.rb', line 24

def complete
  @client.complete_multipart_upload(bucket: @bucket,
                                    key: @destination_file,
                                    upload_id: @upload_id,
                                    multipart_upload: {parts: @parts})
end

#upload(chunk) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/s3_streamer/upstream.rb', line 12

def upload(chunk)
  uploaded_part = @client.upload_part(body: chunk,
                                      bucket: @bucket,
                                      key: @destination_file,
                                      part_number: @part_number,
                                      upload_id: @upload_id)

  @parts << {etag: uploaded_part.etag, part_number: @part_number}

  @part_number += 1
end