Method: Aliyun::OSS::Protocol#append_object

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

#append_object(bucket_name, object_name, position, opts = {}) {|HTTP::StreamWriter| ... } ⇒ Integer

Note:
  1. Can not append to a “Normal Object”

  2. The position must equal to the object’s size before append

  3. The :content_type is only used when the object is created

Append to an object of a bucket. Create an “Appendable Object” if the object does not exist. A block is required to provide the appending data.

Parameters:

  • bucket_name (String)

    the bucket name

  • object_name (String)

    the object name

  • position (Integer)

    the position to append

  • 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

Returns:

  • (Integer)

    next position to append



551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
# File 'lib/aliyun/oss/protocol.rb', line 551

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

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

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

  logger.debug('Done append object')

  wrap(h[:x_oss_next_append_position], &:to_i) || -1
end