Skip to content

Commit

Permalink
gets single file upload size info from stat api
Browse files Browse the repository at this point in the history
  • Loading branch information
Ersan Bozduman committed Dec 14, 2023
1 parent 636739d commit a507ca6
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Minio/ApiEndpoints/ObjectOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ public async Task<PutObjectResponse> 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.
Expand Down Expand Up @@ -847,7 +847,7 @@ await this.ExecuteTaskAsync(ResponseErrorHandlers, requestMessageBuilder,
/// <exception cref="AccessDeniedException">For encrypted PUT operation, Access is denied if the key is wrong</exception>
private async Task<PutObjectResponse> 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();
Expand All @@ -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,
Expand Down

0 comments on commit a507ca6

Please sign in to comment.