Skip to content

Commit

Permalink
RemoveIncompleteUpload with Args.
Browse files Browse the repository at this point in the history
Functional tests, doc changed.
  • Loading branch information
BigUstad committed Nov 20, 2020
1 parent 6953200 commit 345fdc0
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 13 deletions.
12 changes: 7 additions & 5 deletions Docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1539,9 +1539,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 @@ -1550,8 +1550,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 @@ -1570,7 +1569,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 @@ -62,7 +62,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 presignedGetObjectSignature = "Task<string> PresignedGetObjectAsync(PresignedGetObjectArgs args)";
private const string presignedPutObjectSignature = "Task<string> PresignedPutObjectAsync(string bucketName, string objectName, int expiresInt)";
private const string presignedPostPolicySignature = "Task<Dictionary<string, string>> PresignedPostPolicyAsync(PostPolicy policy)";
Expand Down Expand Up @@ -2717,7 +2717,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 @@ -2729,7 +2732,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 @@ -2778,14 +2785,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 @@ -2834,14 +2847,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 @@ -2880,7 +2900,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
42 changes: 42 additions & 0 deletions Minio/ApiEndpoints/ObjectOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,48 @@ private async Task<Tuple<ListMultipartUploadsResult, List<Upload>>> GetMultipart
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">ListIncompleteUploadsArgs 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);
var uploads = await this.ListIncompleteUploads(listUploadArgs, cancellationToken).ToArray();
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
37 changes: 37 additions & 0 deletions Minio/DataModel/ObjectOperationsArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,41 @@ public PresignedGetObjectArgs WithRequestDate(DateTime? d)
return this;
}
}
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;
}
}
}

0 comments on commit 345fdc0

Please sign in to comment.