Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions Minio.Functional.Tests/FunctionalTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3494,13 +3494,19 @@ internal static async Task PutObject_Test9(IMinioClient minio)
var startTime = DateTime.Now;
var bucketName = GetRandomName(15);
var objectName = GetRandomObjectName(10);
var contentType = "application/octet-stream";
const int objSize = 1 * MB;
const string contentType = "application/octet-stream";
var percentage = 0;
var totalBytesTransferred = 0L;
var progress = new Progress<ProgressReport>(progressReport =>
{
percentage = progressReport.Percentage;
totalBytesTransferred = progressReport.TotalBytesTransferred;
// Console.WriteLine(
// $"PutObject_Test9 - Percentage: {progressReport.Percentage}% TotalBytesTransferred: {progressReport.TotalBytesTransferred} bytes");
// if (progressReport.Percentage != 100)
// Console.SetCursorPosition(0, Console.CursorTop - 1);
// else Console.WriteLine();
});
var args = new Dictionary<string, string>
(StringComparer.Ordinal)
Expand All @@ -3514,9 +3520,9 @@ internal static async Task PutObject_Test9(IMinioClient minio)
{
await Setup_Test(minio, bucketName).ConfigureAwait(false);
_ = await PutObject_Tester(minio, bucketName, objectName, null, contentType, 0, null,
rsg.GenerateStreamFromSeed(1 * MB), progress).ConfigureAwait(false);
rsg.GenerateStreamFromSeed(objSize), progress).ConfigureAwait(false);
Assert.IsTrue(percentage == 100);
Assert.IsTrue(totalBytesTransferred == 1 * MB);
Assert.IsTrue(totalBytesTransferred == objSize);
new MintLogger(nameof(PutObject_Test9), putObjectSignature,
"Tests whether PutObject with progress passes for small object", TestStatus.PASS,
DateTime.Now - startTime,
Expand Down Expand Up @@ -3548,11 +3554,11 @@ internal static async Task PutObject_Test10(IMinioClient minio)
{
percentage = progressReport.Percentage;
totalBytesTransferred = progressReport.TotalBytesTransferred;
//Console.WriteLine(
// $"Percentage: {progressReport.Percentage}% TotalBytesTransferred: {progressReport.TotalBytesTransferred} bytes");
//if (progressReport.Percentage != 100)
// Console.WriteLine(
// $"PutObject_Test10 - Percentage: {progressReport.Percentage}% TotalBytesTransferred: {progressReport.TotalBytesTransferred} bytes");
// if (progressReport.Percentage != 100)
// Console.SetCursorPosition(0, Console.CursorTop - 1);
//else Console.WriteLine();
// else Console.WriteLine();
});
var args = new Dictionary<string, string>
(StringComparer.Ordinal)
Expand Down
36 changes: 24 additions & 12 deletions Minio/ApiEndpoints/ObjectOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Net;
using System.Reactive.Linq;
using Minio.ApiEndpoints;
using Minio.DataModel;
Expand Down Expand Up @@ -592,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 @@ -831,6 +832,10 @@ await this.ExecuteTaskAsync(ResponseErrorHandlers, requestMessageBuilder,
/// Headers, SSE Headers
/// </param>
/// <param name="cancellationToken">Optional cancellation token to cancel the operation</param>
/// <param name="singleFile">
/// This boolean parameter differentiates single part file upload and
/// multi part file upload as this function is shared by both.
/// </param>
/// <returns></returns>
/// <exception cref="AuthorizationException">When access or secret key is invalid</exception>
/// <exception cref="InvalidBucketNameException">When bucket name is invalid</exception>
Expand All @@ -841,20 +846,33 @@ await this.ExecuteTaskAsync(ResponseErrorHandlers, requestMessageBuilder,
/// <exception cref="InvalidOperationException">The file stream is currently in a read operation</exception>
/// <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)
CancellationToken cancellationToken = default,
bool singleFile = false)
{
//Skipping validate as we need the case where stream sends 0 bytes
var progressReport = new ProgressReport();
args.Progress?.Report(progressReport);
if (singleFile) args.Progress?.Report(progressReport);
var requestMessageBuilder = await this.CreateRequest(args).ConfigureAwait(false);
using var response =
await this.ExecuteTaskAsync(ResponseErrorHandlers, requestMessageBuilder,
cancellationToken: cancellationToken)
.ConfigureAwait(false);

progressReport.Percentage = 100;
progressReport.TotalBytesTransferred = args.ObjectSize;
args.Progress?.Report(progressReport);
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 = stat.Size;
}

args.Progress.Report(progressReport);
}

return new PutObjectResponse(response.StatusCode, response.Content, response.Headers,
args.ObjectSize, args.ObjectName);
}
Expand Down Expand Up @@ -924,12 +942,6 @@ private async Task<IDictionary<int, string>> PutObjectPartAsync(PutObjectPartArg
return null;
}

if (args.ObjectSize == -1)
{
progressReport.Percentage = 100;
args.Progress?.Report(progressReport);
}

return etags;
}

Expand Down