Method: Aliyun::OSS::Protocol#list_multipart_uploads

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

#list_multipart_uploads(bucket_name, opts = {}) ⇒ Array<Multipart::Transaction>, Hash

Get a list of all the on-going multipart uploading transactions. That is: thoses started and not aborted.

Parameters:

  • bucket_name (String)

    the bucket name

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

    options:

Options Hash (opts):

  • :id_marker (String)

    return only thoese transactions with txn id after :id_marker

  • :key_marker (String)

    the object key marker for a multipart upload transaction.

    1. if :id_marker is not set, return only those transactions with object key after :key_marker;

    2. if :id_marker is set, return only thoese transactions with object key equals :key_marker and txn id after :id_marker

  • :prefix (String)

    the prefix of the object key for a multipart upload transaction. if set only return those transactions with the object key prefixed with it

  • :encoding (String)

    the encoding of object key in the response body. Only KeyEncoding::URL is supported now.

Returns:

  • (Array<Multipart::Transaction>, Hash)

    the returned transactions and a hash including next tokens, which includes:

    • :prefix [String] the prefix used

    • :limit [Integer] the limit used

    • :id_marker [String] the upload id marker used

    • :next_id_marker [String] upload id marker to continue list multipart transactions

    • :key_marker [String] the object key marker used

    • :next_key_marker [String] object key marker to continue list multipart transactions

    • :truncated [Boolean] whether there are more transactions to be returned

    • :encoding [String] the object key encoding used



1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
# File 'lib/aliyun/oss/protocol.rb', line 1270

def list_multipart_uploads(bucket_name, opts = {})
  logger.debug("Begin list multipart uploads, "\
               "bucket: #{bucket_name}, opts: #{opts}")

  sub_res = {'uploads' => nil}
  params = {
    'prefix' => opts[:prefix],
    'upload-id-marker' => opts[:id_marker],
    'key-marker' => opts[:key_marker],
    'max-uploads' => opts[:limit],
    'encoding-type' => opts[:encoding]
  }.reject { |_, v| v.nil? }

  r = @http.get(
    {:bucket => bucket_name, :sub_res => sub_res},
    {:query => params})

  doc = parse_xml(r.body)
  encoding = get_node_text(doc.root, 'EncodingType')
  txns = doc.css("Upload").map do |node|
    Multipart::Transaction.new(
      :id => get_node_text(node, "UploadId"),
      :object => get_node_text(node, "Key") { |x| decode_key(x, encoding) },
      :bucket => bucket_name,
      :creation_time =>
        get_node_text(node, "Initiated") { |t| Time.parse(t) }
    )
  end || []

  more = {
    :prefix => 'Prefix',
    :limit => 'MaxUploads',
    :id_marker => 'UploadIdMarker',
    :next_id_marker => 'NextUploadIdMarker',
    :key_marker => 'KeyMarker',
    :next_key_marker => 'NextKeyMarker',
    :truncated => 'IsTruncated',
    :encoding => 'EncodingType'
  }.reduce({}) { |h, (k, v)|
    value = get_node_text(doc.root, v)
    value.nil?? h : h.merge(k => value)
  }

  update_if_exists(
    more, {
      :limit => ->(x) { x.to_i },
      :truncated => ->(x) { x.to_bool },
      :key_marker => ->(x) { decode_key(x, encoding) },
      :next_key_marker => ->(x) { decode_key(x, encoding) }
    }
  )

  logger.debug("Done list multipart transactions")

  [txns, more]
end