putBucketCORS method

Future<Response> putBucketCORS({
  1. String? bucketName,
  2. String? region,
  3. required COSCORSConfiguration corsConfiguration,
})

PUT Bucket cors 请求用于为存储桶配置跨域资源共享(CORS)访问控制,您可以通过传入 XML 格式的配置文件来实现配置,文件大小限制为64KB bucketName region corsConfiguration

Implementation

Future<Response> putBucketCORS({
  String? bucketName,
  String? region,
  required COSCORSConfiguration corsConfiguration,
}) async {
  final Map<String, String> headers = <String, String>{};
  final String xmlString = corsConfiguration.toXmlString();
  // http 框架设置body时,会自动给 Content-Type 指定字符集为 charset=utf-8
  // 设置 application/xml; charset=utf-8 保持一致
  headers['Content-Type'] = 'application/xml; charset=utf-8';
  headers['Content-Length'] = xmlString.length.toString();
  final String md5String = Base64Encoder()
      .convert(md5.convert(xmlString.codeUnits).bytes)
      .toString();
  headers['Content-MD5'] = md5String;
  final Response response = await client.put(
    '${getBaseApiUrl(bucketName, region)}/?cors',
    headers: headers,
    body: xmlString,
  );
  return toValidation(response);
}