Class: S3::MultipartCreateRequest

Inherits:
Request
  • Object
show all
Defined in:
lib/s3/multipart_create_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



25
26
27
28
29
30
31
32
33
# File 'lib/s3/multipart_create_request.rb', line 25

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

  { bucket: document.at( '//Bucket' )&.text,
    key: document.at( '//Key' )&.text,
    upload_id: document.at( '//UploadId' )&.text
  }
end

#submit(options = nil, bucket:, key:, **kwargs) ⇒ Object



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

def submit( options = nil, bucket:, key:, **kwargs )
  path = "/#{ bucket }/#{ Helpers.encode_key( key ) }"
  query = 'uploads='

  options = merge_options( options, kwargs, MultipartCreateOptions )

  headers = {}
  headers[ 'Content-Type' ] = options[ :content_type ] if options[ :content_type ]
  headers[ 'x-amz-acl' ] = options[ :acl ] if options[ :acl ]
  headers[ 'x-amz-storage-class' ] = options[ :storage_class ] if options[ :storage_class ]

  options[ :metadata ]&.each do | meta_key, value |
    headers[ "x-amz-meta-#{ meta_key }" ] = value.to_s
  end

  response = post( path, query: query, headers: headers )

  build_result( response, MultipartCreateResult ) do
    MultipartCreateResult.new( parse_response( response.body ) )
  end
end