listObjectsV2Query method

Future<ListObjectsV2Output> listObjectsV2Query(
  1. String bucket,
  2. String prefix,
  3. String? continuationToken,
  4. String delimiter,
  5. int? maxKeys,
  6. String? startAfter,
)

listObjectsV2Query - (List Objects V2) - List some or all (up to 1000) of the objects in a bucket.

Implementation

Future<ListObjectsV2Output> listObjectsV2Query(
  String bucket,
  String prefix,
  String? continuationToken,
  String delimiter,
  int? maxKeys,
  String? startAfter,
) async {
  MinioInvalidBucketNameError.check(bucket);
  MinioInvalidPrefixError.check(prefix);

  final queries = <String, dynamic>{};
  queries['prefix'] = prefix;
  queries['delimiter'] = delimiter;
  queries['list-type'] = '2';

  if (continuationToken != null) {
    queries['continuation-token'] = continuationToken;
  }

  if (startAfter != null) {
    queries['start-after'] = startAfter;
  }

  if (maxKeys != null) {
    maxKeys = maxKeys >= 1000 ? 1000 : maxKeys;
    queries['maxKeys'] = maxKeys.toString();
  }

  final resp = await _client.request(
    method: 'GET',
    bucket: bucket,
    queries: queries,
  );

  validate(resp);

  final node = xml.XmlDocument.parse(resp.body);
  final isTruncated = getNodeProp(node.rootElement, 'IsTruncated')!.text;
  final nextContinuationToken =
      getNodeProp(node.rootElement, 'NextContinuationToken')?.text;
  final objs = node.findAllElements('Contents').map((c) => Object.fromXml(c));
  final prefixes = node
      .findAllElements('CommonPrefixes')
      .map((c) => CommonPrefix.fromXml(c));

  return ListObjectsV2Output()
    ..contents = objs.toList()
    ..commonPrefixes = prefixes.toList()
    ..isTruncated = isTruncated.toLowerCase() == 'true'
    ..nextContinuationToken = nextContinuationToken;
}