findUploadId method

Future<String?> findUploadId(
  1. String bucket,
  2. String object
)

Find uploadId of an incomplete upload.

Implementation

Future<String?> findUploadId(String bucket, String object) async {
  MinioInvalidBucketNameError.check(bucket);
  MinioInvalidObjectNameError.check(object);

  MultipartUpload? latestUpload;
  String? keyMarker;
  String? uploadIdMarker;
  bool? isTruncated = false;

  do {
    final result = await listIncompleteUploadsQuery(
      bucket,
      object,
      keyMarker,
      uploadIdMarker,
      '',
    );
    for (var upload in result.uploads) {
      if (upload.key != object) continue;
      if (latestUpload == null ||
          upload.initiated!.isAfter(latestUpload.initiated!)) {
        latestUpload = upload;
      }
    }
    keyMarker = result.nextKeyMarker;
    uploadIdMarker = result.nextUploadIdMarker;
    isTruncated = result.isTruncated;
  } while (isTruncated!);

  return latestUpload?.uploadId;
}