Method: Aliyun::OSS::Protocol#put_object

Defined in:
lib/aliyun/oss/protocol.rb

#put_object(bucket_name, object_name, opts = {}) {|HTTP::StreamWriter| ... } ⇒ Object

Put an object to the specified bucket, a block is required to provide the object data.

Examples:

chunk = get_chunk
put_object('bucket', 'object') { |sw| sw.write(chunk) }

Parameters:

  • bucket_name (String)

    the bucket name

  • object_name (String)

    the object name

  • opts (Hash) (defaults to: {})

    Options

Options Hash (opts):

  • :content_type (String)

    the HTTP Content-Type for the file, if not specified client will try to determine the type itself and fall back to HTTP::DEFAULT_CONTENT_TYPE if it fails to do so

  • :metas (Hash<Symbol, String>)

    key-value pairs that serve as the object meta which will be stored together with the object

Yields:

  • (HTTP::StreamWriter)

    a stream writer is yielded to the caller to which it can write chunks of data streamingly



514
515
516
517
518
519
520
521
522
523
524
525
526
527
# File 'lib/aliyun/oss/protocol.rb', line 514

def put_object(bucket_name, object_name, opts = {}, &block)
  logger.debug("Begin put object, bucket: #{bucket_name}, object: "\
               "#{object_name}, options: #{opts}")

  headers = {'Content-Type' => opts[:content_type]}
  (opts[:metas] || {})
    .each { |k, v| headers["x-oss-meta-#{k.to_s}"] = v.to_s }

  @http.put(
    {:bucket => bucket_name, :object => object_name},
    {:headers => headers, :body => HTTP::StreamPayload.new(&block)})

  logger.debug('Done put object')
end