// 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")
        {
            try
            {
                Console.WriteLine("Running example for API: CopyObjectAsync");

                // Optionally pass copy conditions to replace metadata on destination object with custom metadata
                CopyConditions copyCond = new CopyConditions();
                copyCond.SetReplaceMetadataDirective();

                // set custom metadata
                var metadata = new Dictionary <string, string>
                {
                    { "Content-Type", "application/css" },
                    { "X-Amz-Meta-Mynewkey", "my-new-value" }
                };
                await minio.CopyObjectAsync(fromBucketName,
                                            fromObjectName,
                                            destBucketName,
                                            destObjectName,
                                            copyConditions : copyCond,
                                            metadata : metadata);

                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);
            }
        }
示例#2
0
    // 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}");
        }
    }