listObjectsV2Query method
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) {
final keys = maxKeys >= 1000 ? 1000 : maxKeys;
queries['maxKeys'] = keys.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')!.innerText;
final nextContinuationToken =
getNodeProp(node.rootElement, 'NextContinuationToken')?.innerText;
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;
}