From a507ca62002c0604f7042468052e582a5ecd73b0 Mon Sep 17 00:00:00 2001 From: Ersan Bozduman Date: Thu, 14 Dec 2023 04:34:28 -0800 Subject: [PATCH] gets single file upload size info from stat api --- Minio/ApiEndpoints/ObjectOperations.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Minio/ApiEndpoints/ObjectOperations.cs b/Minio/ApiEndpoints/ObjectOperations.cs index 24d5a1d5..ebcb9cc5 100644 --- a/Minio/ApiEndpoints/ObjectOperations.cs +++ b/Minio/ApiEndpoints/ObjectOperations.cs @@ -593,7 +593,7 @@ public async Task PutObjectAsync(PutObjectArgs args, args = args.WithRequestBody(bytes) .WithStreamData(null) .WithObjectSize(bytesRead); - return await PutObjectSinglePartAsync(args, cancellationToken).ConfigureAwait(false); + return await PutObjectSinglePartAsync(args, cancellationToken, true).ConfigureAwait(false); } // For all sizes greater than 5MiB do multipart. @@ -847,7 +847,7 @@ await this.ExecuteTaskAsync(ResponseErrorHandlers, requestMessageBuilder, /// For encrypted PUT operation, Access is denied if the key is wrong private async Task PutObjectSinglePartAsync(PutObjectArgs args, CancellationToken cancellationToken = default, - bool singleFile = true) + bool singleFile = false) { //Skipping validate as we need the case where stream sends 0 bytes var progressReport = new ProgressReport(); @@ -858,15 +858,19 @@ await this.ExecuteTaskAsync(ResponseErrorHandlers, requestMessageBuilder, cancellationToken: cancellationToken) .ConfigureAwait(false); - if (singleFile) + if (singleFile && args.Progress is not null) { + var statArgs = new StatObjectArgs() + .WithBucket(args.BucketName) + .WithObject(args.ObjectName); + var stat = await StatObjectAsync(statArgs, cancellationToken).ConfigureAwait(false); if (response.StatusCode == HttpStatusCode.OK) { progressReport.Percentage = 100; - progressReport.TotalBytesTransferred = args.ObjectSize; + progressReport.TotalBytesTransferred = stat.Size; } - args.Progress?.Report(progressReport); + args.Progress.Report(progressReport); } return new PutObjectResponse(response.StatusCode, response.Content, response.Headers,