Class: S3::MultipartCompleteRequest

Inherits:
Request
  • Object
show all
Defined in:
lib/s3/multipart_complete_request.rb

Constant Summary

Constants inherited from Request

Request::AWS_ALGORITHM, Request::AWS_REQUEST, Request::SERVICE, Request::UNSIGNED_PAYLOAD

Instance Method Summary collapse

Methods inherited from Request

#initialize

Constructor Details

This class inherits a constructor from S3::Request

Instance Method Details

#parse_response(body) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/s3/multipart_complete_request.rb', line 27

def parse_response( body )
  document = parse_xml( body )
  document.remove_namespaces!

  { location: document.at( '//Location' )&.text,
    bucket: document.at( '//Bucket' )&.text,
    key: document.at( '//Key' )&.text,
    etag: document.at( '//ETag' )&.text&.tr( '"', '' )
  }
end

#submit(bucket:, key:, upload_id:, parts:) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/s3/multipart_complete_request.rb', line 3

def submit( bucket:, key:, upload_id:, parts: )
  path = "/#{ bucket }/#{ Helpers.encode_key( key ) }"
  query = Helpers.build_query_string( 'uploadId' => upload_id )

  parts_xml = parts.sort_by { | part | part[ :part_number ] || part[ 'part_number' ] }.map do | part |
    part_num = part[ :part_number ] || part[ 'part_number' ]
    etag = part[ :etag ] || part[ 'etag' ]
    "<Part><PartNumber>#{ part_num }</PartNumber><ETag>#{ etag }</ETag></Part>"
  end.join

  body = "    <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n    <CompleteMultipartUpload xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">\n      \#{ parts_xml }\n    </CompleteMultipartUpload>\n  XML\n\n  response = post( path, body: body, query: query )\n\n  build_result( response, MultipartCompleteResult ) do\n    MultipartCompleteResult.new( parse_response( response.body ) )\n  end\nend\n"