From 930bc6675f5dfa507142ee4a444f771c0697c5d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=81=20=E4=BB=BB?= Date: Thu, 20 Mar 2025 08:28:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9C=AA=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E5=AE=8C=E6=9F=A5=E8=AF=A2=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test.xaml | 1 + test.xaml.cs | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/test.xaml b/test.xaml index 75a1af7..791465f 100644 --- a/test.xaml +++ b/test.xaml @@ -13,6 +13,7 @@ Title="test" Height="450" Width="800"> + diff --git a/test.xaml.cs b/test.xaml.cs index d3d1b7d..6a89660 100644 --- a/test.xaml.cs +++ b/test.xaml.cs @@ -19,6 +19,9 @@ using Minio.DataModel.Encryption; using Microsoft.WindowsAPICodePack.Dialogs; using System.IO; using System.Diagnostics; +using Minio.Exceptions; +using System.Threading; +using System.Security.AccessControl; namespace Hopetry { /// @@ -30,6 +33,7 @@ namespace Hopetry public test() { InitializeComponent(); + // 配置 MinIO 客户端 client = new Minio.MinioClient() .WithEndpoint("123.132.248.154:9107") // MinIO 服务器地址 @@ -215,6 +219,51 @@ namespace Hopetry { } + + private async void Button_Click_1(object sender, RoutedEventArgs e) + { + try + { + string bucketName = "test"; + + // 检查存储桶是否存在,如果不存在则创建 + var beArgs = new BucketExistsArgs().WithBucket(bucketName); + // Check whether 'mybucket' exist or not. + bool found = await client.BucketExistsAsync(beArgs).ConfigureAwait(false); + if (found) + { + // List all incomplete multipart upload of objects in 'mybucket' + ListIncompleteUploadsArgs listArgs = new ListIncompleteUploadsArgs() + .WithBucket("test") + .WithRecursive(true); + IAsyncEnumerable observable = client.ListIncompleteUploadsEnumAsync(listArgs); + //IDisposable subscription = observable.Subscribe( + // item => Console.WriteLine("OnNext: {0}", item.Key), + // ex => Console.WriteLine("OnError: {0}", ex.Message), + // () => Console.WriteLine("OnComplete: {0}")); + + await foreach (var upload in observable) + { + // 在这里查看每个 Upload 对象 + Console.WriteLine($"Upload ID: {upload.UploadId}, Object Name: {upload.Key}"); + var statObjectArgs = new StatObjectArgs() + .WithBucket(bucketName) + .WithObject(upload.Key); + + // Get object metadata if it exists + var objectStat = await client.StatObjectAsync(statObjectArgs); + } + } + else + { + Console.WriteLine("mybucket does not exist"); + } + } + catch (MinioException ex) + { + Console.WriteLine("Error occurred: " + ex); + } + } } } \ No newline at end of file