getBucketRegion method

Future<String> getBucketRegion(
  1. String bucket
)

gets the region of the bucket

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.text;
  if (location.isEmpty) {
    location = 'us-east-1';
  }

  _regionMap[bucket] = location;
  return location;
}