Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 1-minio-dotnet-geto…
Browse files Browse the repository at this point in the history
…bject
  • Loading branch information
BigUstad committed Dec 6, 2020
2 parents b4494df + 802e5f1 commit cdeade3
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 25 deletions.
12 changes: 7 additions & 5 deletions Docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1496,9 +1496,9 @@ catch (MinioException e)
```

<a name="removeIncompleteUpload"></a>
### RemoveIncompleteUploadAsync(string bucketName, string objectName)
### RemoveIncompleteUploadAsync(RemoveIncompleteUploadArgs args)

`Task RemoveIncompleteUploadAsync(string bucketName, string objectName, CancellationToken cancellationToken = default(CancellationToken))`
`Task RemoveIncompleteUploadAsync(RemoveIncompleteUploadArgs args, CancellationToken cancellationToken = default(CancellationToken))`

Removes a partially uploaded object.

Expand All @@ -1507,8 +1507,7 @@ __Parameters__

|Param | Type | Description |
|:--- |:--- |:--- |
| ``bucketName`` | _string_ | Name of the bucket |
| ``objectName`` | _string_ | Object name in the bucket |
| ``args`` | _RemoveIncompleteUploadArgs_ | RemoveIncompleteUploadArgs object encapsulating the bucket, object names |
| ``cancellationToken``| _System.Threading.CancellationToken_ | Optional parameter. Defaults to default(CancellationToken) |


Expand All @@ -1527,7 +1526,10 @@ __Example__
try
{
// Removes partially uploaded objects from buckets.
await minioClient.RemoveIncompleteUploadAsync("mybucket", "myobject");
RemoveIncompleteUploadArgs args = new RemoveIncompleteUploadArgs()
.WithBucket(bucketName)
.WithObject(objectName);
await minioClient.RemoveIncompleteUploadAsync(args);
Console.WriteLine("successfully removed all incomplete upload session of my-bucketname/my-objectname");
}
catch(MinioException e)
Expand Down
39 changes: 31 additions & 8 deletions Minio.Functional.Tests/FunctionalTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class FunctionalTest
private const string copyObjectSignature = "Task<CopyObjectResult> CopyObjectAsync(string bucketName, string objectName, string destBucketName, string destObjectName = null, CopyConditions copyConditions = null, CancellationToken cancellationToken = default(CancellationToken))";
private const string removeObjectSignature1 = "Task RemoveObjectAsync(string bucketName, string objectName, CancellationToken cancellationToken = default(CancellationToken))";
private const string removeObjectSignature2 = "Task<IObservable<DeleteError>> RemoveObjectAsync(string bucketName, IEnumerable<string> objectsList, CancellationToken cancellationToken = default(CancellationToken))";
private const string removeIncompleteUploadSignature = "Task RemoveIncompleteUploadAsync(string bucketName, string objectName, CancellationToken cancellationToken = default(CancellationToken))";
private const string removeIncompleteUploadSignature = "Task RemoveIncompleteUploadAsync(RemoveIncompleteUploadArgs args, CancellationToken cancellationToken = default(CancellationToken))";
private const string presignedPutObjectSignature = "Task<string> PresignedPutObjectAsync(PresignedPutObjectArgs args)";
private const string presignedGetObjectSignature = "Task<string> PresignedGetObjectAsync(PresignedGetObjectArgs args)";
private const string presignedPostPolicySignature = "Task<Dictionary<string, string>> PresignedPostPolicyAsync(PresignedPostPolicyArgs args)";
Expand Down Expand Up @@ -2850,7 +2850,10 @@ await minio.PutObjectAsync(bucketName,
Assert.Fail();
});

await minio.RemoveIncompleteUploadAsync(bucketName, objectName);
RemoveIncompleteUploadArgs rmArgs = new RemoveIncompleteUploadArgs()
.WithBucket(bucketName)
.WithObject(objectName);
await minio.RemoveIncompleteUploadAsync(rmArgs);
}
catch (Exception ex)
{
Expand All @@ -2862,7 +2865,11 @@ await minio.PutObjectAsync(bucketName,
}
catch (MinioException ex)
{
await minio.RemoveIncompleteUploadAsync(bucketName, objectName);
RemoveIncompleteUploadArgs rmArgs = new RemoveIncompleteUploadArgs()
.WithBucket(bucketName)
.WithObject(objectName);

await minio.RemoveIncompleteUploadAsync(rmArgs);
await TearDown(minio, bucketName);
new MintLogger("ListIncompleteUpload_Test1", listIncompleteUploadsSignature, "Tests whether ListIncompleteUpload passes", TestStatus.FAIL, (DateTime.Now - startTime), ex.Message, ex.ToString()).Log();
}
Expand Down Expand Up @@ -2911,14 +2918,20 @@ await minio.PutObjectAsync(bucketName,
item => Assert.AreEqual(item.Key, objectName),
ex => Assert.Fail());

await minio.RemoveIncompleteUploadAsync(bucketName, objectName);
RemoveIncompleteUploadArgs rmArgs = new RemoveIncompleteUploadArgs()
.WithBucket(bucketName)
.WithObject(objectName);
await minio.RemoveIncompleteUploadAsync(rmArgs);
}
await TearDown(minio, bucketName);
new MintLogger("ListIncompleteUpload_Test2", listIncompleteUploadsSignature, "Tests whether ListIncompleteUpload passes when qualified by prefix", TestStatus.PASS, (DateTime.Now - startTime), args:args).Log();
}
catch (MinioException ex)
{
await minio.RemoveIncompleteUploadAsync(bucketName, objectName);
RemoveIncompleteUploadArgs rmArgs = new RemoveIncompleteUploadArgs()
.WithBucket(bucketName)
.WithObject(objectName);
await minio.RemoveIncompleteUploadAsync(rmArgs);
await TearDown(minio, bucketName);
new MintLogger("ListIncompleteUpload_Test2", listIncompleteUploadsSignature, "Tests whether ListIncompleteUpload passes when qualified by prefix", TestStatus.FAIL, (DateTime.Now - startTime), ex.Message, ex.ToString(), args:args).Log();
}
Expand Down Expand Up @@ -2967,14 +2980,21 @@ await minio.PutObjectAsync(bucketName,
item => Assert.AreEqual(item.Key, objectName),
ex => Assert.Fail());

await minio.RemoveIncompleteUploadAsync(bucketName, objectName);
RemoveIncompleteUploadArgs rmArgs = new RemoveIncompleteUploadArgs()
.WithBucket(bucketName)
.WithObject(objectName);
await minio.RemoveIncompleteUploadAsync(rmArgs);
}
await TearDown(minio, bucketName);
new MintLogger("ListIncompleteUpload_Test3", listIncompleteUploadsSignature, "Tests whether ListIncompleteUpload passes when qualified by prefix and recursive", TestStatus.PASS, (DateTime.Now - startTime), args:args).Log();
}
catch (MinioException ex)
{
await minio.RemoveIncompleteUploadAsync(bucketName, objectName);
RemoveIncompleteUploadArgs rmArgs = new RemoveIncompleteUploadArgs()
.WithBucket(bucketName)
.WithObject(objectName);

await minio.RemoveIncompleteUploadAsync(rmArgs);
await TearDown(minio, bucketName);
new MintLogger("ListIncompleteUpload_Test3", listIncompleteUploadsSignature, "Tests whether ListIncompleteUpload passes when qualified by prefix and recursive", TestStatus.FAIL, (DateTime.Now - startTime), ex.Message, ex.ToString(), args:args).Log();
}
Expand Down Expand Up @@ -3013,7 +3033,10 @@ await minio.PutObjectAsync(bucketName,
}
catch (OperationCanceledException)
{
await minio.RemoveIncompleteUploadAsync(bucketName, objectName);
RemoveIncompleteUploadArgs rmArgs = new RemoveIncompleteUploadArgs()
.WithBucket(bucketName)
.WithObject(objectName);
await minio.RemoveIncompleteUploadAsync(rmArgs);

ListIncompleteUploadsArgs listArgs = new ListIncompleteUploadsArgs()
.WithBucket(bucketName);
Expand Down
88 changes: 77 additions & 11 deletions Minio/ApiEndpoints/ObjectOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,16 @@ public partial class MinioClient : IObjectOperations
Tuple<ListMultipartUploadsResult, List<Upload>> uploads = null;
try
{
uploads = await this.GetMultipartUploadsListAsync(getArgs, cancellationToken).ConfigureAwait(false);
uploads = await this.GetMultipartUploadsListAsync(getArgs, cancellationToken).ConfigureAwait(false);
}
catch (Exception ex)
catch (Exception)
{
if (ex.GetType() == typeof(BucketNotFoundException))
{
isRunning = false;
continue;
}
throw;
throw;
}
if (uploads == null)
{
isRunning = false;
continue;
}
foreach (Upload upload in uploads.Item2)
{
Expand All @@ -148,20 +148,86 @@ public partial class MinioClient : IObjectOperations
/// <summary>
/// Get list of multi-part uploads matching particular uploadIdMarker
/// </summary>
/// <param name="args">ListIncompleteUploadsArgs Arguments Object which encapsulates bucket name, prefix, recursive</param>
/// <param name="args">GetMultipartUploadsListArgs Arguments Object which encapsulates bucket name, prefix, recursive</param>
/// <param name="cancellationToken">Optional cancellation token to cancel the operation</param>
/// <returns></returns>
private async Task<Tuple<ListMultipartUploadsResult, List<Upload>>> GetMultipartUploadsListAsync(GetMultipartUploadsListArgs args,
CancellationToken cancellationToken)
{
args.Validate();
IRestResponse response = null;
RestRequest request = await this.CreateRequest(args).ConfigureAwait(false);
response = await this.ExecuteAsync(this.NoErrorHandlers, request, cancellationToken).ConfigureAwait(false);
try
{
RestRequest request = await this.CreateRequest(args).ConfigureAwait(false);
response = await this.ExecuteAsync(this.NoErrorHandlers, request, cancellationToken).ConfigureAwait(false);
}
catch (Exception)
{
throw;
}
GetMultipartUploadsListResponse getUploadResponse = new GetMultipartUploadsListResponse(response.StatusCode, response.Content);
return getUploadResponse.UploadResult;
}


/// <summary>
/// Remove object with matching uploadId from bucket
/// </summary>
/// <param name="args">RemoveUploadArgs Arguments Object which encapsulates bucket, object names, upload Id</param>
/// <param name="cancellationToken">Optional cancellation token to cancel the operation</param>
/// <returns></returns>
private async Task RemoveUploadAsync(RemoveUploadArgs args, CancellationToken cancellationToken)
{
args.Validate();
RestRequest request = await this.CreateRequest(args).ConfigureAwait(false);
await this.ExecuteAsync(this.NoErrorHandlers, request, cancellationToken).ConfigureAwait(false);
}


/// <summary>
/// Remove incomplete uploads from a given bucket and objectName
/// </summary>
/// <param name="args">RemoveIncompleteUploadArgs Arguments Object which encapsulates bucket, object names</param>
/// <param name="cancellationToken">Optional cancellation token to cancel the operation</param>
/// <returns></returns>
public async Task RemoveIncompleteUploadAsync(RemoveIncompleteUploadArgs args, CancellationToken cancellationToken = default(CancellationToken))
{
args.Validate();
ListIncompleteUploadsArgs listUploadArgs = new ListIncompleteUploadsArgs()
.WithBucket(args.BucketName)
.WithPrefix(args.ObjectName);

Upload[] uploads = null;
try
{
uploads = await this.ListIncompleteUploads(listUploadArgs, cancellationToken)?.ToArray();
}
catch (Exception ex)
{
//Bucket Not found. So, incomplete uploads are removed.
if (ex.GetType() != typeof(BucketNotFoundException))
{
throw ex;
}
}
if (uploads == null)
{
return;
}
foreach (var upload in uploads)
{
if(upload.Key.ToLower().Equals(args.ObjectName.ToLower()))
{
RemoveUploadArgs rmArgs = new RemoveUploadArgs()
.WithBucket(args.BucketName)
.WithObject(args.ObjectName)
.WithUploadId(upload.UploadId);
await this.RemoveUploadAsync(rmArgs, cancellationToken).ConfigureAwait(false);
}
}
}


/// Presigned get url - returns a presigned url to access an object's data without credentials.URL can have a maximum expiry of
/// upto 7 days or a minimum of 1 second.Additionally, you can override a set of response headers using reqParams.
/// </summary>
Expand Down
57 changes: 57 additions & 0 deletions Minio/DataModel/ObjectOperationsArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,44 @@ public PresignedPutObjectArgs WithExpiry(int ex)
}
}

public class RemoveUploadArgs : EncryptionArgs<RemoveUploadArgs>
{
internal string UploadId { get; private set; }
public RemoveUploadArgs()
{
this.RequestMethod = Method.DELETE;
}

public RemoveUploadArgs WithUploadId(string id)
{
this.UploadId = id;
return this;
}

public override void Validate()
{
base.Validate();
if(string.IsNullOrEmpty(this.UploadId))
{
throw new InvalidOperationException(nameof(UploadId) + " cannot be empty. Please assign a valid upload ID to remove.");
}
}
public override RestRequest BuildRequest(RestRequest request)
{
request = base.BuildRequest(request);
request.AddQueryParameter("uploadId",$"{this.UploadId}");
return request;
}
}

public class RemoveIncompleteUploadArgs : EncryptionArgs<RemoveIncompleteUploadArgs>
{
public RemoveIncompleteUploadArgs()
{
this.RequestMethod = Method.DELETE;
}
}

public class GetObjectArgs : ObjectQueryArgs<GetObjectArgs>
{
internal Action<Stream> CallBack { get; private set; }
Expand All @@ -382,6 +420,7 @@ public GetObjectArgs()
public override void Validate()
{
base.Validate();
<<<<<<< HEAD
if (this.CallBack == null)
{
throw new MinioException("CallBack method not set of GetObject operation.");
Expand All @@ -401,11 +440,17 @@ public override void Validate()
if (this.FileName != null)
{
utils.ValidateFile(this.FileName);
=======
if(string.IsNullOrEmpty(this.UploadId))
{
throw new InvalidOperationException(nameof(UploadId) + " cannot be empty. Please assign a valid upload ID to remove.");
>>>>>>> origin/master
}
}
public override RestRequest BuildRequest(RestRequest request)
{
request = base.BuildRequest(request);
<<<<<<< HEAD
var headers = new Dictionary<string, string>();
if (this.SSE != null && this.SSE.GetType().Equals(EncryptionType.SSE_C))
{
Expand Down Expand Up @@ -439,6 +484,18 @@ public GetObjectArgs WithFile(string file)
{
this.FileName = file;
return this;
=======
request.AddQueryParameter("uploadId",$"{this.UploadId}");
return request;
}
}

public class RemoveIncompleteUploadArgs : EncryptionArgs<RemoveIncompleteUploadArgs>
{
public RemoveIncompleteUploadArgs()
{
this.RequestMethod = Method.DELETE;
>>>>>>> origin/master
}
}
}
2 changes: 1 addition & 1 deletion Minio/DataModel/ObjectOperationsResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
using System.IO;
using System.Linq;
using System.Net;
using System.Xml.Serialization;
using RestSharp;

using Minio.DataModel;
using System.Xml.Serialization;

namespace Minio
{
Expand Down

0 comments on commit cdeade3

Please sign in to comment.