// 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) .WithTagging(Tagging.GetObjectTags(tags)) .WithReplaceTagsDirective(true) .WithCopyObjectSource(cpSrcArgs); await minio.CopyObjectAsync(args).ConfigureAwait(false); } catch (Exception e) { Console.WriteLine("[Bucket] Exception: {0}", e); } }
// Copy object from one bucket to another 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", ServerSideEncryption sseSrc = null, ServerSideEncryption sseDest = null) { try { Console.WriteLine("Running example for API: CopyObjectAsync"); var metaData = new Dictionary <string, string> { { "Test-Metadata", "Test Test" } }; // Optionally pass copy conditions 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(); } catch (Exception e) { Console.WriteLine("[Bucket] Exception: {0}", e); } }
// Copy object from one bucket to another public static async 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"); // Optionally pass copy conditions to replace metadata on destination object with custom metadata var copyCond = new CopyConditions(); copyCond.SetReplaceMetadataDirective(); // set custom metadata var metadata = new Dictionary <string, string> { { "Content-Type", "application/css" }, { "Mynewkey", "my-new-value" } }; var copySourceObjectArgs = new CopySourceObjectArgs() .WithBucket(fromBucketName) .WithObject(fromObjectName) .WithCopyConditions(copyCond); var 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(); } catch (Exception e) { Console.WriteLine($"[Bucket] Exception: {e}"); } }
public async Task <bool> CopyObjectAsync(string bucketName, string objectName, string destBucketName = null, string destObjectName = null) { if (string.IsNullOrEmpty(bucketName)) { throw new ArgumentNullException(nameof(bucketName)); } objectName = FormatObjectName(objectName); if (string.IsNullOrEmpty(destBucketName)) { destBucketName = bucketName; } destObjectName = FormatObjectName(destObjectName); CopySourceObjectArgs cpSrcArgs = new CopySourceObjectArgs() .WithBucket(bucketName) .WithObject(objectName); CopyObjectArgs args = new CopyObjectArgs() .WithBucket(destBucketName) .WithObject(destObjectName) .WithCopyObjectSource(cpSrcArgs); await _client.CopyObjectAsync(args); return(true); }