getBucketRegion method

Future<String> getBucketRegion(
  1. String bucket
)

Gets the region of bucket. The region is cached for subsequent calls.

Implementation

Future<String> getBucketRegion(String bucket) async {
  MinioInvalidBucketNameError.check(bucket);

  if (region != null) {
    return region!;
  }

  if (_regionMap.containsKey(bucket)) {
    return _regionMap[bucket]!;
  }

  final resp = await _client.request(
    method: 'GET',
    bucket: bucket,
    region: 'us-east-1',
    queries: <String, dynamic>{'location': null},
  );

  validate(resp);

  final node = xml.XmlDocument.parse(resp.body);

  var location = node.findAllElements('LocationConstraint').first.innerText;
  // if (location == null || location.isEmpty) {
  if (location.isEmpty) {
    location = 'us-east-1';
  }

  _regionMap[bucket] = location;
  return location;
}