private async static Task CopyObject_Test1(MinioClient minio) { Console.Out.WriteLine("Test1: CopyObjectsAsync"); string bucketName = GetRandomName(15); string objectName = GetRandomName(10); string destBucketName = GetRandomName(15); string destObjectName = GetRandomName(10); string fileName = CreateFile(1 * MB); await Setup_Test(minio, bucketName); await Setup_Test(minio, destBucketName); await minio.PutObjectAsync(bucketName, objectName, fileName); await minio.CopyObjectAsync(bucketName, objectName, destBucketName, destObjectName); string outFileName = "outFileName"; await minio.GetObjectAsync(destBucketName, destObjectName, outFileName); File.Delete(outFileName); await minio.RemoveObjectAsync(bucketName, objectName); await minio.RemoveObjectAsync(destBucketName, destObjectName); await TearDown(minio, bucketName); await TearDown(minio, destBucketName); File.Delete(fileName); Console.Out.WriteLine("Test1: CopyObjectsAsync Complete"); }
// 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, 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); } }
//Copies content from objectName to destObjectName. public Task CopyObjectFromToAsync(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)) { try { /* * CopyConditions copyConditions = new CopyConditions(); * copyConditions.setMatchETagNone("TestETag"); * ServerSideEncryption sseSrc, sseDst; */ // Uncomment to specify source and destination Server-side encryption options /* * Aes aesEncryption = Aes.Create(); * aesEncryption.KeySize = 256; * aesEncryption.GenerateKey(); * sseSrc = new SSEC(aesEncryption.Key); * sseDst = new SSES3(); */ var taskCopyObj = minio.CopyObjectAsync(bucketName, objectName, destBucketName, destObjectName, copyConditions, metadata, sseSrc, sseDest, cancellationToken); return(taskCopyObj); } catch (MinioException e) { throw; } }
// 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); } }
// 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"); // Optionally pass copy conditions await minio.CopyObjectAsync(fromBucketName, fromObjectName, destBucketName, destObjectName, copyConditions : null, sseSrc : sseSrc, sseDest : sseDest); 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); } }
public async Task <bool> CopyFileAsync(string path, string targetPath, CancellationToken cancellationToken = default) { if (String.IsNullOrEmpty(path)) { throw new ArgumentNullException(nameof(path)); } if (String.IsNullOrEmpty(targetPath)) { throw new ArgumentNullException(nameof(targetPath)); } await EnsureBucketExists().AnyContext(); try { var copySourceArgs = new CopySourceObjectArgs().WithBucket(_bucket).WithObject(NormalizePath(path)); await _client.CopyObjectAsync(new CopyObjectArgs() .WithBucket(_bucket) .WithObject(NormalizePath(targetPath)) .WithCopyObjectSource(copySourceArgs), cancellationToken).AnyContext(); return(true); } catch (Exception ex) { _logger.LogError(ex, "Error trying to copy file {Path} to {TargetPath}.", path, targetPath); return(false); } }
private async static Task CopyObject_Test3(MinioClient minio) { Console.Out.WriteLine("Test3: CopyObjectsAsync"); // Test CopyConditions where matching ETag is found string bucketName = GetRandomName(15); string objectName = GetRandomName(10); string destBucketName = GetRandomName(15); string destObjectName = GetRandomName(10); string fileName = CreateFile(1 * MB); await Setup_Test(minio, bucketName); await Setup_Test(minio, destBucketName); await minio.PutObjectAsync(bucketName, objectName, fileName); ObjectStat stats = await minio.StatObjectAsync(bucketName, objectName); CopyConditions conditions = new CopyConditions(); conditions.SetMatchETag(stats.ETag); try { await minio.CopyObjectAsync(bucketName, objectName, destBucketName, destObjectName, conditions); } catch (MinioException) { Assert.Fail(); } string outFileName = "outFileName"; ObjectStat dstats = await minio.StatObjectAsync(destBucketName, destObjectName); Assert.IsNotNull(dstats); Assert.AreEqual(dstats.ETag, stats.ETag); Assert.AreEqual(dstats.ObjectName, destObjectName); await minio.GetObjectAsync(destBucketName, destObjectName, outFileName); File.Delete(outFileName); await minio.RemoveObjectAsync(bucketName, objectName); await minio.RemoveObjectAsync(destBucketName, destObjectName); await TearDown(minio, bucketName); await TearDown(minio, destBucketName); File.Delete(fileName); Console.Out.WriteLine("Test3: CopyObjectsAsync Complete"); }
public void RenameFile(string bucketName, string source, string target) { try { m_client.CopyObjectAsync(bucketName, source, bucketName, target).Await(); } catch (MinioException e) { Logging.Log.WriteErrorMessage(Logtag, "ErrorCopyingObjectMinio", null, "Error copying object {0} to {1} in bucket {2} using Minio: {3}", source, target, bucketName, e.ToString()); } DeleteObject(bucketName, source); }
private async static Task CopyObject_Test5(MinioClient minio) { // Test if multi-part copy upload for large files works as expected. Console.Out.WriteLine("Test5: CopyObjectsAsync"); string bucketName = GetRandomName(15); string objectName = GetRandomName(10); string destBucketName = GetRandomName(15); string fileName = CreateFile(7 * MB); await Setup_Test(minio, bucketName); await Setup_Test(minio, destBucketName); await minio.PutObjectAsync(bucketName, objectName, fileName); CopyConditions conditions = new CopyConditions(); conditions.SetByteRange(1024, 6291456); // omit dest object name. await minio.CopyObjectAsync(bucketName, objectName, destBucketName, copyConditions : conditions); string outFileName = "outFileName"; await minio.GetObjectAsync(bucketName, objectName, outFileName); File.Delete(outFileName); ObjectStat stats = await minio.StatObjectAsync(destBucketName, objectName); Assert.IsNotNull(stats); Assert.AreEqual(stats.ObjectName, objectName); Assert.AreEqual(stats.Size, 6291456 - 1024 + 1); await minio.RemoveObjectAsync(bucketName, objectName); await minio.RemoveObjectAsync(destBucketName, objectName); await TearDown(minio, bucketName); await TearDown(minio, destBucketName); File.Delete(fileName); Console.Out.WriteLine("Test4: CopyObjectsAsync Complete"); }
private async static Task CopyObject_Test4(MinioClient minio) { // Test if objectName is defaulted to source objectName Console.Out.WriteLine("Test4: CopyObjectsAsync"); string bucketName = GetRandomName(15); string objectName = GetRandomName(10); string destBucketName = GetRandomName(15); string fileName = CreateFile(1 * MB); await Setup_Test(minio, bucketName); await Setup_Test(minio, destBucketName); await minio.PutObjectAsync(bucketName, objectName, fileName); CopyConditions conditions = new CopyConditions(); conditions.SetMatchETag("TestETag"); // omit dest bucket name. await minio.CopyObjectAsync(bucketName, objectName, destBucketName); string outFileName = "outFileName"; await minio.GetObjectAsync(bucketName, objectName, outFileName); File.Delete(outFileName); ObjectStat stats = await minio.StatObjectAsync(destBucketName, objectName); Assert.IsNotNull(stats); Assert.AreEqual(stats.ObjectName, objectName); await minio.RemoveObjectAsync(bucketName, objectName); await minio.RemoveObjectAsync(destBucketName, objectName); await TearDown(minio, bucketName); await TearDown(minio, destBucketName); File.Delete(fileName); Console.Out.WriteLine("Test4: CopyObjectsAsync Complete"); }
public async Task <UploadResponse> FileUploadCopy(List <TempFilesToDestination> content) { var bucketName = this.bucket; UploadResponse obj = new UploadResponse(); try { var minio = new MinioClient(this.endpoint, accessKey, accessSecret); // Make a bucket on the server, if not already present. bool found = await minio.BucketExistsAsync(bucketName); if (!found) { await minio.MakeBucketAsync(bucketName, this.location); } foreach (var item in content) { try { await minio.StatObjectAsync(bucketName, item.distObjectName); } catch (MinioException e) { await minio.CopyObjectAsync(bucketName, item.tempObjectName, bucketName, item.distObjectName); await minio.RemoveObjectAsync(bucketName, item.tempObjectName); } } obj.Message = "Uploaded Successfully."; obj.HasSucceed = true; } catch (MinioException e) { Console.WriteLine("File Upload Error: {0}", e.Message); obj.Message = "Uploaded failed with error " + e.message; obj.HasSucceed = false; obj.FileUrl = this.BaseUrl + bucketName + "/"; } return(obj); }
// 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> CopyFileAsync(string path, string targetPath, CancellationToken cancellationToken = default) { if (String.IsNullOrEmpty(path)) { throw new ArgumentNullException(nameof(path)); } if (String.IsNullOrEmpty(targetPath)) { throw new ArgumentNullException(nameof(targetPath)); } try { await _client.CopyObjectAsync(_bucket, NormalizePath(path), _bucket, NormalizePath(targetPath), null, null, null, null, cancellationToken).AnyContext(); return(true); } catch (Exception ex) { _logger.LogError(ex, "Error trying to copy file {Path} to {TargetPath}.", path, targetPath); return(false); } }
private async static Task CopyObject_Test2(MinioClient minio) { Console.Out.WriteLine("Test2: CopyObjectsAsync"); // Test CopyConditions where matching ETag is not found string bucketName = GetRandomName(15); string objectName = GetRandomName(10); string destBucketName = GetRandomName(15); string destObjectName = GetRandomName(10); string fileName = CreateFile(1 * MB); await Setup_Test(minio, bucketName); await Setup_Test(minio, destBucketName); await minio.PutObjectAsync(bucketName, objectName, fileName); CopyConditions conditions = new CopyConditions(); conditions.SetMatchETag("TestETag"); try { await minio.CopyObjectAsync(bucketName, objectName, destBucketName, destObjectName, conditions); } catch (MinioException ex) { Assert.AreEqual(ex.Message, "Minio API responded with message=At least one of the pre-conditions you specified did not hold"); } await minio.RemoveObjectAsync(bucketName, objectName); await TearDown(minio, bucketName); await TearDown(minio, destBucketName); File.Delete(fileName); Console.Out.WriteLine("Test2: CopyObjectsAsync Complete"); }
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); }
/// <summary> /// Efetua a copia de um objeto no servidor, evitando a necessidade de efetuar um upload. /// </summary> /// <param name="bucketName">Nome do balde de origem da copia.</param> /// <param name="objectName">Nome do objecto de origem da copia.</param> /// <param name="destBucketName">Balde de destino</param> /// <param name="destObjectName">Objeto de destino</param> /// <returns>Tarefa sendo executada.</returns> public Task CopyObjectAsync(string bucketName, string objectName, string destBucketName, string destObjectName) { ValidateInstance(); return(_minioClient.CopyObjectAsync(bucketName, objectName, destBucketName, destObjectName)); }
/// <summary> /// Efetua a copia de um objeto no servidor, evitando a necessidade de efetuar um upload. /// </summary> /// <param name="bucketName">Nome do balde de origem da copia.</param> /// <param name="objectName">Nome do objecto de origem da copia.</param> /// <param name="destBucketName">Balde de destino</param> /// <param name="destObjectName">Objeto de destino</param> /// <returns>Tarefa sendo executada.</returns> public override async Task CopyObjectAsync(string bucketName, string objectName, string destBucketName, string destObjectName) { ValidateInstance(); await _minioClient.CopyObjectAsync(bucketName, objectName, destBucketName, destObjectName).ConfigureAwait(false); }
private async Task <string> moveObject(string input, MinioClient minio) { var request = getTaskFromDb(input); if (request.ContainsKey("error")) { return(request.ToString()); } var bucket = request["params"]["bucket"].Value <string>(); var file = request["params"]["object"].Value <string>(); var newBucket = request["params"]["newBucket"].Value <string>(); bool found = await minio.BucketExistsAsync(newBucket); if (!found) { await minio.MakeBucketAsync(newBucket); } string result = string.Empty; minio.CopyObjectAsync(bucket, file, newBucket).ContinueWith((x) => { if (x.IsFaulted) { StringBuilder sb = new StringBuilder(); sb.AppendLine(x.Exception.Message); foreach (var e in x.Exception.InnerExceptions) { sb.AppendLine(e.Message); } result = sb.ToString(); } else { Console.WriteLine($"Object {file} copied to {newBucket} successfully"); var key = Guid.NewGuid().ToString(); var callJson = new JObject( new JProperty("_key", key), new JProperty("params", new JObject( new JProperty("bucket", bucket), new JProperty("object", file), new JProperty("topic", "augury")) )); writeTaskToDb(callJson); string callResponse = string.Empty; makeCallAsync("kafkawriter", key).ContinueWith(c => { if (x.IsFaulted) { callResponse = $"Error calling objectmover for {file}: {c.Exception.Message}"; } else { callResponse = c.Result; } Console.WriteLine($"{input}: {callResponse}"); }).Wait(); result = callResponse; } }) .Wait(); return(result); }