Skip to content

Commit

Permalink
Add builder pattern support for CopyObject API. (#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
BigUstad authored Feb 2, 2021
1 parent f33fed4 commit 97324ef
Show file tree
Hide file tree
Showing 12 changed files with 929 additions and 131 deletions.
20 changes: 9 additions & 11 deletions Docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -2075,9 +2075,9 @@ catch(MinioException e)
```

<a name="copyObject"></a>
### CopyObjectAsync(string bucketName, string objectName, string destBucketName, string destObjectName = null, CopyConditions copyConditions = null, Dictionary<string, string> metadata = null, ServerSideEncryption sseSrc = null, ServerSideEncryption sseDest = null)
### CopyObjectAsync(CopyObjectArgs args)

*`Task<CopyObjectResult> CopyObjectAsync(string bucketName, string objectName, string destBucketName, string destObjectName = null, CopyConditions copyConditions = null, Dictionary<string, string> metadata = null, ServerSideEncryption sseSrc = null, ServerSideEncryption sseDest = null, CancellationToken cancellationToken = default(CancellationToken))`*
*`Task<CopyObjectResult> CopyObjectAsync(CopyObjectArgs args, CancellationToken cancellationToken = default(CancellationToken))`*

Copies content from objectName to destObjectName.

Expand All @@ -2087,21 +2087,19 @@ __Parameters__

|Param | Type | Description |
|:--- |:--- |:--- |
| ``bucketName`` | _string_ | Name of the source bucket |
| ``objectName`` | _string_ | Object name in the source bucket to be copied |
| ``destBucketName`` | _string_ | Destination bucket name |
| ``destObjectName`` | _string_ | Destination object name to be created, if not provided defaults to source object name|
| ``copyConditions`` | _CopyConditions_ | Map of conditions useful for applying restrictions on copy operation|
| ``metadata`` | _Dictionary<string,string>_ | Dictionary of meta data headers and their values on the destination side.Defaults to null.|
| ``sseSrc`` | _ServerSideEncryption_ | Server-side encryption option for source object | Optional parameter. Defaults to null |
| ``sseDest`` | _ServerSideEncryption_ | Server-side encryption option for destination object| Optional parameter. Defaults to null |
| ``args`` | _CopyObjectArgs_ | Arguments object - bucket name, object name, destination bucket name, destination object name, copy conditions, metadata, Source SSE, Destination SSE. etc. |
| ``cancellationToken``| _System.Threading.CancellationToken_ | Optional parameter. Defaults to default(CancellationToken) |


| Return Type | Exceptions |
|:--- |:--- |
| ``Task`` | Listed Exceptions: |
| | ``InvalidBucketNameException`` : upon invalid bucket name |
| | ``AuthorizationException`` : upon access or secret key wrong or not found |
| | ``InvalidBucketNameException`` : upon invalid bucket name |
| | ``InvalidObjectNameException`` : upon invalid object name |
| | ``BucketNotFoundException`` : upon bucket with name not found |
| | ``ObjectNotFoundException`` : upon object with name not found |
| | ``MalFormedXMLException`` : upon configuration XML in http request validation failure |
| | ``ConnectionException`` : upon connection error |
| | ``InternalClientException`` : upon internal library error |
| | ``ArgumentException`` : upon missing bucket/object names |
Expand Down
26 changes: 17 additions & 9 deletions Minio.Examples/Cases/CopyObject.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* MinIO .NET Library for Amazon S3 Compatible Cloud Storage, (C) 2017 MinIO, Inc.
* MinIO .NET Library for Amazon S3 Compatible Cloud Storage, (C) 2017-2021 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,7 @@

using Minio.DataModel;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Minio.Examples.Cases
Expand All @@ -34,14 +35,21 @@ public async static Task Run(MinioClient minio,
try
{
Console.WriteLine("Running example for API: CopyObjectAsync");
var metaData = new Dictionary<string, string>
{
{ "Test-Metadata", "Test Test" }
};
// Optionally pass copy conditions
await minio.CopyObjectAsync(fromBucketName,
fromObjectName,
destBucketName,
destObjectName,
copyConditions: null,
sseSrc: sseSrc,
sseDest: sseDest);
CopySourceObjectArgs cpSrcArgs = new CopySourceObjectArgs()
.WithBucket(fromBucketName)
.WithObject(fromObjectName)
.WithServerSideEncryption(sseSrc);
CopyObjectArgs args = new CopyObjectArgs()
.WithBucket(destBucketName)
.WithObject(destObjectName)
.WithCopyObjectSource(cpSrcArgs)
.WithServerSideEncryption(sseDest);
await minio.CopyObjectAsync(args);
Console.WriteLine("Copied object {0} from bucket {1} to bucket {2}", fromObjectName, fromBucketName, destBucketName);
Console.WriteLine();
}
Expand All @@ -51,4 +59,4 @@ await minio.CopyObjectAsync(fromBucketName,
}
}
}
}
}
18 changes: 11 additions & 7 deletions Minio.Examples/Cases/CopyObjectMetadata.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* MinIO .NET Library for Amazon S3 Compatible Cloud Storage, (C) 2018 MinIO, Inc.
* MinIO .NET Library for Amazon S3 Compatible Cloud Storage, (C) 2018-2021 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -45,12 +45,16 @@ public async static Task Run(MinioClient minio,
{ "Mynewkey", "my-new-value" }
};

await minio.CopyObjectAsync(fromBucketName,
fromObjectName,
destBucketName,
destObjectName,
copyConditions:copyCond,
metadata: metadata);
CopySourceObjectArgs copySourceObjectArgs = new CopySourceObjectArgs()
.WithBucket(fromBucketName)
.WithObject(fromObjectName)
.WithCopyConditions(copyCond);
CopyObjectArgs copyObjectArgs = new CopyObjectArgs()
.WithBucket(destBucketName)
.WithObject(destObjectName)
.WithHeaders(metadata)
.WithCopyObjectSource(copySourceObjectArgs);
await minio.CopyObjectAsync(copyObjectArgs);

Console.WriteLine($"Copied object {fromObjectName} from bucket {fromBucketName} to bucket {destBucketName}");
Console.WriteLine();
Expand Down
57 changes: 57 additions & 0 deletions Minio.Examples/Cases/CopyObjectReplaceTags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* MinIO .NET Library for Amazon S3 Compatible Cloud Storage, (C) 2017-2021 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading.Tasks;

namespace Minio.Examples.Cases
{
class CopyObjectReplaceTags
{
// Copy object from one bucket to another, replace tags in the copied object
public async static Task Run(MinioClient minio,
string fromBucketName = "from-bucket-name",
string fromObjectName = "from-object-name",
string destBucketName = "dest-bucket",
string destObjectName =" to-object-name")
{
try
{
Console.WriteLine("Running example for API: CopyObjectAsync with Tags");
var tags = new Dictionary<string, string>
{
{ "Test-TagKey", "Test-TagValue" },
};
CopySourceObjectArgs cpSrcArgs = new CopySourceObjectArgs()
.WithBucket(fromBucketName)
.WithObject(fromObjectName);
CopyObjectArgs args = new CopyObjectArgs()
.WithBucket(destBucketName)
.WithObject(destObjectName)
.WithTagKeyValuePairs(tags)
.WithReplaceTagsDirective(true)
.WithCopyObjectSource(cpSrcArgs);
await minio.CopyObjectAsync(args).ConfigureAwait(false);
}
catch (Exception e)
{
Console.WriteLine("[Bucket] Exception: {0}", e);
}
}
}
}
Loading

0 comments on commit 97324ef

Please sign in to comment.