copyObject method

Future<CopyObjectResult> copyObject(
  1. String bucket,
  2. String object,
  3. String srcObject, [
  4. CopyConditions? conditions,
])

Copy the object.

Implementation

Future<CopyObjectResult> copyObject(
  String bucket,
  String object,
  String srcObject, [
  CopyConditions? conditions,
]) async {
  MinioInvalidBucketNameError.check(bucket);
  MinioInvalidObjectNameError.check(object);
  MinioInvalidObjectNameError.check(srcObject);

  final headers = <String, String>{};
  headers['x-amz-copy-source'] = srcObject;

  if (conditions != null) {
    if (conditions.modified != null) {
      headers['x-amz-copy-source-if-modified-since'] = conditions.modified!;
    }
    if (conditions.unmodified != null) {
      headers['x-amz-copy-source-if-unmodified-since'] =
          conditions.unmodified!;
    }
    if (conditions.matchETag != null) {
      headers['x-amz-copy-source-if-match'] = conditions.matchETag!;
    }
    if (conditions.matchETagExcept != null) {
      headers['x-amz-copy-source-if-none-match'] =
          conditions.matchETagExcept!;
    }
  }

  final resp = await _client.request(
    method: 'PUT',
    bucket: bucket,
    object: object,
    headers: headers,
  );

  validate(resp);

  final node = xml.XmlDocument.parse(resp.body);
  final result = CopyObjectResult.fromXml(node.rootElement);
  result.eTag = trimDoubleQuote(result.eTag!);
  return result;
}