Class: S3::ObjectPutRequest

Inherits:
Request
  • Object
show all
Defined in:
lib/s3/object_put_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(response) ⇒ Object



29
30
31
32
33
34
# File 'lib/s3/object_put_request.rb', line 29

def parse_response( response )
  {
    etag: response.headers[ 'etag' ]&.tr( '"', '' ),
    version_id: response.headers[ 'x-amz-version-id' ]
  }
end

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



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

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

  options = merge_options( options, kwargs, ObjectPutOptions )

  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 ]
  headers[ 'Cache-Control' ] = options[ :cache_control ] if options[ :cache_control ]
  headers[ 'Content-Disposition' ] = options[ :content_disposition ] if options[ :content_disposition ]
  headers[ 'Content-Encoding' ] = options[ :content_encoding ] if options[ :content_encoding ]
  headers[ 'Content-Language' ] = options[ :content_language ] if options[ :content_language ]
  headers[ 'Expires' ] = options[ :expires ].httpdate if options[ :expires ]

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

  response = put( path, body: body, headers: headers )

  build_result( response, ObjectPutResult ) do
    ObjectPutResult.new( parse_response( response ) )
  end
end