diff --git a/TestMinio/TestMinio.sln b/TestMinio/TestMinio.sln new file mode 100644 index 0000000..c61379e --- /dev/null +++ b/TestMinio/TestMinio.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33530.505 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestMinio", "TestMinio\TestMinio.csproj", "{038EC1C3-69E7-4685-AD58-23F52483FD3A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test2", "test2\test2.csproj", "{3392789A-A741-4A1F-BD65-EF5A6AED65C4}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {038EC1C3-69E7-4685-AD58-23F52483FD3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {038EC1C3-69E7-4685-AD58-23F52483FD3A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {038EC1C3-69E7-4685-AD58-23F52483FD3A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {038EC1C3-69E7-4685-AD58-23F52483FD3A}.Release|Any CPU.Build.0 = Release|Any CPU + {3392789A-A741-4A1F-BD65-EF5A6AED65C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3392789A-A741-4A1F-BD65-EF5A6AED65C4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3392789A-A741-4A1F-BD65-EF5A6AED65C4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3392789A-A741-4A1F-BD65-EF5A6AED65C4}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {802A8E72-28F2-450D-BA12-EE533BB99968} + EndGlobalSection +EndGlobal diff --git a/TestMinio/TestMinio/App.config b/TestMinio/TestMinio/App.config new file mode 100644 index 0000000..3bf71e9 --- /dev/null +++ b/TestMinio/TestMinio/App.config @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TestMinio/TestMinio/Form1.Designer.cs b/TestMinio/TestMinio/Form1.Designer.cs new file mode 100644 index 0000000..ba0e636 --- /dev/null +++ b/TestMinio/TestMinio/Form1.Designer.cs @@ -0,0 +1,87 @@ +namespace TestMinio +{ + partial class Form1 + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要修改 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.button1 = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(305, 212); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(153, 72); + this.button1.TabIndex = 0; + this.button1.Text = "上传"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(333, 169); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(89, 12); + this.label1.TabIndex = 1; + this.label1.Text = "当前无选择文件"; + // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(547, 80); + this.textBox1.Multiline = true; + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(219, 285); + this.textBox1.TabIndex = 0; + this.textBox1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.AutoScroll = true; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.label1); + this.Controls.Add(this.button1); + this.Name = "Form1"; + this.Text = "Form1"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox textBox1; + } +} + diff --git a/TestMinio/TestMinio/Form1.cs b/TestMinio/TestMinio/Form1.cs new file mode 100644 index 0000000..f06d512 --- /dev/null +++ b/TestMinio/TestMinio/Form1.cs @@ -0,0 +1,98 @@ +using System; +using System.Threading.Tasks; +using System.Windows.Forms; +using Minio; +using Minio.Exceptions; + +namespace TestMinio +{ + public partial class Form1 : Form + { + static string endpoint = "10.40.18.12:9000"; + static string accessKey = "root"; + static string secretKey = "root_password"; + // Initialize the client with access credentials. + private static MinioClient minio = new MinioClient() + .WithEndpoint(endpoint) + .WithCredentials(accessKey, secretKey) + .Build(); + + // Create an async task for listing buckets. + + public Form1() + { + InitializeComponent(); + } + + private async void button1_Click(object sender, EventArgs e) + { + // Create an async task for listing buckets. + var getListBucketsTask = await minio.ListBucketsAsync().ConfigureAwait(true); + + // Iterate over the list of buckets. + foreach (var bucket in getListBucketsTask.Buckets) + { + Console.WriteLine($"{bucket.Name} {bucket.CreationDateDateTime} \n"); + textBox1.Text += $"{bucket.Name} {bucket.CreationDateDateTime} \n"; + } + + using (OpenFileDialog openFileDialog = new OpenFileDialog()) + { + // 设置文件对话框的标题 + openFileDialog.Title = "选择要上传的文件"; + + // 设置文件对话框允许选择的文件类型(例如:图片、文本文件等) + openFileDialog.Filter = "All Files (*.*)|*.*"; + + // 设置是否允许选择多个文件 + openFileDialog.Multiselect = false; + + // 打开文件对话框,并等待用户选择文件 + if (openFileDialog.ShowDialog() == DialogResult.OK) + { + // 获取选择的文件路径并显示在 TextBox 中 + label1.Text = openFileDialog.FileName; + Run(openFileDialog.FileName); + + } + } + } + + private async Task Run(String filePath) + { + var bucketName = "hbl"; + var objectName = System.IO.Path.GetFileName(filePath); + var contentType = "application/zip"; + + try + { + // Make a bucket on the server, if not already present. + var beArgs = new BucketExistsArgs() + .WithBucket(bucketName); + bool found = await minio.BucketExistsAsync(beArgs).ConfigureAwait(false); + if (!found) + { + var mbArgs = new MakeBucketArgs() + .WithBucket(bucketName); + await minio.MakeBucketAsync(mbArgs).ConfigureAwait(false); + } + // Upload a file to bucket. + var putObjectArgs = new PutObjectArgs() + .WithBucket(bucketName) + .WithObject(objectName) + .WithFileName(filePath); + await minio.PutObjectAsync(putObjectArgs).ConfigureAwait(false); + Console.WriteLine("Successfully uploaded " + objectName); + var url =$"http://{endpoint}/hbl/{objectName}"; + MessageBox.Show(url); + Console.WriteLine(url); + return url; + } + catch (MinioException e) + { + Console.WriteLine("File Upload Error: {0}", e.Message); + } + return $"上传失败"; + } + } +} diff --git a/TestMinio/TestMinio/Form1.resx b/TestMinio/TestMinio/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/TestMinio/TestMinio/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TestMinio/TestMinio/Program.cs b/TestMinio/TestMinio/Program.cs new file mode 100644 index 0000000..c8aa434 --- /dev/null +++ b/TestMinio/TestMinio/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace TestMinio +{ + internal static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/TestMinio/TestMinio/Properties/AssemblyInfo.cs b/TestMinio/TestMinio/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..82f70f4 --- /dev/null +++ b/TestMinio/TestMinio/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("TestMinio")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("TestMinio")] +[assembly: AssemblyCopyright("Copyright © 2023")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("038ec1c3-69e7-4685-ad58-23f52483fd3a")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 +//通过使用 "*",如下所示: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/TestMinio/TestMinio/Properties/Resources.Designer.cs b/TestMinio/TestMinio/Properties/Resources.Designer.cs new file mode 100644 index 0000000..31e9187 --- /dev/null +++ b/TestMinio/TestMinio/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能导致不正确的行为,如果 +// 重新生成代码,则所做更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace TestMinio.Properties +{ + + + /// + /// 强类型资源类,用于查找本地化字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// 返回此类使用的缓存 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TestMinio.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 重写当前线程的 CurrentUICulture 属性,对 + /// 使用此强类型资源类的所有资源查找执行重写。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/TestMinio/TestMinio/Properties/Resources.resx b/TestMinio/TestMinio/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/TestMinio/TestMinio/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TestMinio/TestMinio/Properties/Settings.Designer.cs b/TestMinio/TestMinio/Properties/Settings.Designer.cs new file mode 100644 index 0000000..366e688 --- /dev/null +++ b/TestMinio/TestMinio/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace TestMinio.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/TestMinio/TestMinio/Properties/Settings.settings b/TestMinio/TestMinio/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/TestMinio/TestMinio/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/TestMinio/TestMinio/TestMinio.csproj b/TestMinio/TestMinio/TestMinio.csproj new file mode 100644 index 0000000..4803cc4 --- /dev/null +++ b/TestMinio/TestMinio/TestMinio.csproj @@ -0,0 +1,173 @@ + + + + + Debug + AnyCPU + {038EC1C3-69E7-4685-AD58-23F52483FD3A} + WinExe + TestMinio + TestMinio + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\CommunityToolkit.HighPerformance.8.1.0\lib\netstandard2.0\CommunityToolkit.HighPerformance.dll + True + + + ..\packages\Microsoft.Bcl.AsyncInterfaces.7.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll + + + ..\packages\Microsoft.Bcl.HashCode.1.1.1\lib\net461\Microsoft.Bcl.HashCode.dll + + + ..\packages\Minio.5.0.0\lib\netstandard2.0\Minio.dll + True + + + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + + + ..\packages\System.IO.4.3.0\lib\net462\System.IO.dll + True + True + + + ..\packages\System.IO.Hashing.7.0.0\lib\net462\System.IO.Hashing.dll + + + ..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll + + + ..\packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll + True + True + + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + ..\packages\System.Reactive.5.0.0\lib\net472\System.Reactive.dll + + + ..\packages\System.Reactive.Linq.5.0.0\lib\net472\System.Reactive.Linq.dll + + + ..\packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll + True + True + + + ..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + + ..\packages\System.Security.Cryptography.Algorithms.4.3.1\lib\net463\System.Security.Cryptography.Algorithms.dll + True + True + + + ..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll + True + True + + + ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll + True + True + + + ..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll + True + True + + + ..\packages\System.Text.Encodings.Web.7.0.0\lib\net462\System.Text.Encodings.Web.dll + + + ..\packages\System.Text.Json.7.0.2\lib\net462\System.Text.Json.dll + + + ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll + + + ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + + + + \ No newline at end of file diff --git a/TestMinio/TestMinio/lib/CommunityToolkit.HighPerformance.dll b/TestMinio/TestMinio/lib/CommunityToolkit.HighPerformance.dll new file mode 100644 index 0000000..a8e240e Binary files /dev/null and b/TestMinio/TestMinio/lib/CommunityToolkit.HighPerformance.dll differ diff --git a/TestMinio/TestMinio/lib/Minio.dll b/TestMinio/TestMinio/lib/Minio.dll new file mode 100644 index 0000000..c2c02da Binary files /dev/null and b/TestMinio/TestMinio/lib/Minio.dll differ diff --git a/TestMinio/TestMinio/packages.config b/TestMinio/TestMinio/packages.config new file mode 100644 index 0000000..6ca643e --- /dev/null +++ b/TestMinio/TestMinio/packages.config @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TestMinio/test2/App.config b/TestMinio/test2/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/TestMinio/test2/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/TestMinio/test2/Form1.Designer.cs b/TestMinio/test2/Form1.Designer.cs new file mode 100644 index 0000000..e63ed23 --- /dev/null +++ b/TestMinio/test2/Form1.Designer.cs @@ -0,0 +1,125 @@ +namespace TestMinio +{ + partial class Form1 + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要修改 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.button1 = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.button2 = new System.Windows.Forms.Button(); + this.treeView = new System.Windows.Forms.TreeView(); + this.button3 = new System.Windows.Forms.Button(); + this.button4 = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(82, 233); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(153, 72); + this.button1.TabIndex = 0; + this.button1.Text = "上传"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(109, 202); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(89, 12); + this.label1.TabIndex = 1; + this.label1.Text = "当前无选择文件"; + // + // button2 + // + this.button2.Location = new System.Drawing.Point(584, 233); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(153, 72); + this.button2.TabIndex = 2; + this.button2.Text = "下载"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // treeView + // + this.treeView.Location = new System.Drawing.Point(267, 5); + this.treeView.Name = "treeView"; + this.treeView.Size = new System.Drawing.Size(288, 433); + this.treeView.TabIndex = 4; + // + // button3 + // + this.button3.Location = new System.Drawing.Point(584, 104); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(153, 72); + this.button3.TabIndex = 5; + this.button3.Text = "删除"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); + // + // button4 + // + this.button4.Location = new System.Drawing.Point(82, 104); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(153, 72); + this.button4.TabIndex = 6; + this.button4.Text = "刷新文件列表"; + this.button4.UseVisualStyleBackColor = true; + this.button4.Click += new System.EventHandler(this.button4_Click); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.AutoScroll = true; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.button4); + this.Controls.Add(this.button3); + this.Controls.Add(this.treeView); + this.Controls.Add(this.button2); + this.Controls.Add(this.label1); + this.Controls.Add(this.button1); + this.Name = "Form1"; + this.Text = "Form1"; + this.Load += new System.EventHandler(this.Form1_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.TreeView treeView; + private System.Windows.Forms.Button button3; + private System.Windows.Forms.Button button4; + } +} + diff --git a/TestMinio/test2/Form1.cs b/TestMinio/test2/Form1.cs new file mode 100644 index 0000000..0d9de6b --- /dev/null +++ b/TestMinio/test2/Form1.cs @@ -0,0 +1,200 @@ +using System; +using System.IO; +using System.Threading.Tasks; +using System.Windows.Forms; +using Minio; +using Minio.DataModel; +using Minio.Exceptions; +using test2; +using static System.Net.Mime.MediaTypeNames; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; + +namespace TestMinio +{ + public partial class Form1 : Form + { + static string endpoint = "10.40.18.12:9000"; + static string accessKey = "root"; + static string secretKey = "root_password"; + // Initialize the client with access credentials. + private static MinioClient minio = new MinioClient() + .WithEndpoint(endpoint) + .WithCredentials(accessKey, secretKey) + .Build(); + + // Create an async task for listing buckets. + + public Form1() + { + InitializeComponent(); + } + + + private async void button1_Click(object sender, EventArgs e) + { + // Create an async task for listing buckets. + var getListBucketsTask = await minio.ListBucketsAsync().ConfigureAwait(true); + + // Iterate over the list of buckets. + foreach (var bucket in getListBucketsTask.Buckets) + { + Console.WriteLine($"{bucket.Name} {bucket.CreationDateDateTime} \n"); + } + + using (OpenFileDialog openFileDialog = new OpenFileDialog()) + { + // 设置文件对话框的标题 + openFileDialog.Title = "选择要上传的文件"; + + // 设置文件对话框允许选择的文件类型(例如:图片、文本文件等) + openFileDialog.Filter = "All Files (*.*)|*.*"; + + // 设置是否允许选择多个文件 + openFileDialog.Multiselect = false; + + // 打开文件对话框,并等待用户选择文件 + if (openFileDialog.ShowDialog() == DialogResult.OK) + { + // 获取选择的文件路径并显示在 TextBox 中 + label1.Text = openFileDialog.FileName; + // Run(openFileDialog.FileName); + await MinioFileManager.UploadFileAsync(openFileDialog.FileName); + loadBucket(); + } + } + } + + private async Task Run(String filePath) + { + var bucketName = $"hbl"; + var objectName = System.IO.Path.GetFileName(filePath); + var contentType = "application/zip"; + + try + { + // Make a bucket on the server, if not already present. + var beArgs = new BucketExistsArgs() + .WithBucket(bucketName); + bool found = await minio.BucketExistsAsync(beArgs).ConfigureAwait(false); + if (!found) + { + var mbArgs = new MakeBucketArgs() + .WithBucket(bucketName); + await minio.MakeBucketAsync(mbArgs).ConfigureAwait(false); + } + // Upload a file to bucket. + var putObjectArgs = new PutObjectArgs() + .WithBucket(bucketName) + .WithObject($"{DateTime.Now.ToString("yyyy-MM-dd")}/{objectName}") + .WithFileName(filePath); + await minio.PutObjectAsync(putObjectArgs).ConfigureAwait(false); + Console.WriteLine("Successfully uploaded " + objectName); + var url =$"http://{endpoint}/hbl/{DateTime.Now.ToString("yyyy-MM-dd")}/{objectName}"; + MessageBox.Show(url); + Console.WriteLine(url); + return url; + } + catch (MinioException e) + { + Console.WriteLine("File Upload Error: {0}", e.Message); + } + return $"上传失败"; + } + + private async void button2_Click(object sender, EventArgs e) + { + var val= getNodeVal(); + if (val == null) return; + await MinioFileManager.DownloadFileAsync(val); + MessageBox.Show("下载成功"); + } + + private string getNodeVal() { + //await MinioFileManager.DownloadFileAsync("2023-08-10/200406113500-7.jpg"); + TreeNode selectedNode = treeView.SelectedNode; + if (selectedNode != null) + { + if (selectedNode.Nodes.Count == 0) + { + // 选定的是叶子节点,拼接完整文件路径 + string fullPath = GetFullPath(selectedNode); + return fullPath; + // MessageBox.Show("选定的叶子节点的完整路径:" + fullPath, "完整文件路径", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + // 选定的不是叶子节点,清除选定节点 + treeView.SelectedNode = null; + MessageBox.Show("没有选定节点!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + } + else + { + MessageBox.Show("没有选定节点!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + return null; + } + private string GetFullPath(TreeNode node) + { + string fullPath = node.Text; + TreeNode parentNode = node.Parent; + while (parentNode != null) + { + fullPath = $"{parentNode.Text}/{fullPath}"; + parentNode = parentNode.Parent; + } + return fullPath; + } + private void loadBucket() { + treeView.Nodes.Clear(); + MinioFileManager.ListObjects(item => { + //textBox1.Invoke(new Action(() => textBox1.Text += $"{item.Key}\n")); + //textBox1.Text += $"{item.Key}\n"; + treeView.Invoke(new Action(() => PopulateTreeView(item.Key))); + }); + } + + private void PopulateTreeView(String filePath) + { + string[] pathSegments = filePath.Split('/'); + + TreeNode currentNode = null; + TreeNodeCollection nodes = treeView.Nodes; + + foreach (string segment in pathSegments) + { + TreeNode[] matchingNodes = nodes.Find(segment, false); + + if (matchingNodes.Length > 0) + { + currentNode = matchingNodes[0]; + } + else + { + currentNode = nodes.Add(segment, segment); + } + + nodes = currentNode.Nodes; + } + } + + private void Form1_Load(object sender, EventArgs e) + { + loadBucket(); + } + + private async void button3_Click(object sender, EventArgs e) + { + var val = getNodeVal(); + if (val == null) return; + await MinioFileManager.DeleteFileAsync(val); + MessageBox.Show("删除成功"); + loadBucket(); + } + + private void button4_Click(object sender, EventArgs e) + { + loadBucket(); + } + } +} diff --git a/TestMinio/test2/Form1.resx b/TestMinio/test2/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/TestMinio/test2/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TestMinio/test2/MinioFileManager.cs b/TestMinio/test2/MinioFileManager.cs new file mode 100644 index 0000000..6cb6566 --- /dev/null +++ b/TestMinio/test2/MinioFileManager.cs @@ -0,0 +1,128 @@ +using Minio; +using Minio.DataModel; +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection.Emit; +using System.Threading.Tasks; +using System.Windows.Forms; +using static System.Net.WebRequestMethods; + + +namespace test2 +{ + class MinioFileManager + { + private static string endpoint = "10.40.18.12:9000"; + private static string accessKey = "root"; + private static string secretKey = "root_password"; + private static string bucketName = "hbl"; + private static string url = $"http://{endpoint}/hbl"; + private static MinioClient minioClient=new MinioClient().WithEndpoint(endpoint) + .WithCredentials(accessKey, secretKey) + .Build(); + // Initialize the client with access credentials. + + private static string getObjectNameByUrl(String input) { + + if (input.StartsWith(url)) + { + string desiredContent = input.Substring(url.Length); + return desiredContent; + } + else + { + return input; + } + } + + public static async Task UploadFileAsync(string filePath,string objectName=null) + { + if (!await minioClient.BucketExistsAsync(new BucketExistsArgs() + .WithBucket(bucketName))) + { + await minioClient.MakeBucketAsync(new MakeBucketArgs() + .WithBucket(bucketName)); + } + if (objectName == null) objectName = System.IO.Path.GetFileName(filePath); + objectName = $"{DateTime.Now.ToString("yyyy-MM-dd")}/{objectName}"; + var putObjectArgs = new PutObjectArgs() + .WithBucket(bucketName) + .WithObject(objectName) + .WithFileName(filePath); + await minioClient.PutObjectAsync(putObjectArgs); + return $"{url}/{objectName}"; + } + + public static async Task DeleteFileAsync(string inputUrl) + { + await minioClient.RemoveObjectAsync(new RemoveObjectArgs() + .WithBucket(bucketName).WithObject(getObjectNameByUrl(inputUrl))); + } + + + /// 列出存储桶里的对象 + /// 列出存储桶里的对象 + /// + /// 连接实例 + /// 存储桶名称 + /// 对象的前缀 + /// true代表递归查找,false代表类似文件夹查找,以'/'分隔,不查子文件夹 + public static IObservable ListObjects(Action action,string prefix = null, bool recursive = true) + { + try + { + ListObjectsArgs args = new ListObjectsArgs() + .WithBucket(bucketName) + .WithPrefix(prefix) + .WithRecursive(recursive); + + IObservable observable = minioClient.ListObjectsAsync(args); + var subscription = observable.Subscribe(new MyObserver(action)); + return observable; + } + catch (Exception e) + { + throw new Exception(e.Message); + } + } + class MyObserver : IObserver + { + private Action action; + public MyObserver(Action action) { + this.action = action; + } + public void OnCompleted() + { + Console.WriteLine("Completed"); + } + + public void OnError(Exception error) + { + Console.WriteLine("Error: " + error.Message); + } + + public void OnNext(Item value) + { + action(value); + Console.WriteLine("Next: " + value.Key); + } + } + public static async Task DownloadFileAsync(string objectName) + { + var saveFileDialog = new SaveFileDialog(); + string fileExtension = Path.GetExtension(objectName); + saveFileDialog.FileName = $"{DateTime.Now.ToString("yyyyMMddHHmmss")}"+ fileExtension; + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + saveFileDialog.Filter = "All Files (*.*)|*.*"; + var stat = await minioClient.GetObjectAsync(new GetObjectArgs() + .WithBucket(bucketName) + .WithObject(getObjectNameByUrl(objectName)) + .WithFile(saveFileDialog.FileName)); + MessageBox.Show("下载成功"); + } + } + } + +} diff --git a/TestMinio/test2/Program.cs b/TestMinio/test2/Program.cs new file mode 100644 index 0000000..805b9fe --- /dev/null +++ b/TestMinio/test2/Program.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; +using TestMinio; + +namespace test2 +{ + internal static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/TestMinio/test2/Properties/AssemblyInfo.cs b/TestMinio/test2/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..89ed9cf --- /dev/null +++ b/TestMinio/test2/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("test2")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("test2")] +[assembly: AssemblyCopyright("Copyright © 2023")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("3392789a-a741-4a1f-bd65-ef5a6aed65c4")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 +//通过使用 "*",如下所示: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/TestMinio/test2/Properties/Resources.Designer.cs b/TestMinio/test2/Properties/Resources.Designer.cs new file mode 100644 index 0000000..cedee12 --- /dev/null +++ b/TestMinio/test2/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能导致不正确的行为,如果 +// 重新生成代码,则所做更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace test2.Properties +{ + + + /// + /// 强类型资源类,用于查找本地化字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// 返回此类使用的缓存 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("test2.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 重写当前线程的 CurrentUICulture 属性,对 + /// 使用此强类型资源类的所有资源查找执行重写。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/TestMinio/test2/Properties/Resources.resx b/TestMinio/test2/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/TestMinio/test2/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TestMinio/test2/Properties/Settings.Designer.cs b/TestMinio/test2/Properties/Settings.Designer.cs new file mode 100644 index 0000000..724aea0 --- /dev/null +++ b/TestMinio/test2/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace test2.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/TestMinio/test2/Properties/Settings.settings b/TestMinio/test2/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/TestMinio/test2/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/TestMinio/test2/lib/CommunityToolkit.HighPerformance.dll b/TestMinio/test2/lib/CommunityToolkit.HighPerformance.dll new file mode 100644 index 0000000..a8e240e Binary files /dev/null and b/TestMinio/test2/lib/CommunityToolkit.HighPerformance.dll differ diff --git a/TestMinio/test2/lib/Minio.dll b/TestMinio/test2/lib/Minio.dll new file mode 100644 index 0000000..c2c02da Binary files /dev/null and b/TestMinio/test2/lib/Minio.dll differ diff --git a/TestMinio/test2/lib/System.Reactive.dll b/TestMinio/test2/lib/System.Reactive.dll new file mode 100644 index 0000000..ec69a7f Binary files /dev/null and b/TestMinio/test2/lib/System.Reactive.dll differ diff --git a/TestMinio/test2/lib/System.Text.Json.dll b/TestMinio/test2/lib/System.Text.Json.dll new file mode 100644 index 0000000..cd85864 Binary files /dev/null and b/TestMinio/test2/lib/System.Text.Json.dll differ diff --git a/TestMinio/test2/test2.csproj b/TestMinio/test2/test2.csproj new file mode 100644 index 0000000..f2cf2a4 --- /dev/null +++ b/TestMinio/test2/test2.csproj @@ -0,0 +1,102 @@ + + + + + Debug + AnyCPU + {3392789A-A741-4A1F-BD65-EF5A6AED65C4} + WinExe + test2 + test2 + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + ..\TestMinio\lib\Minio.dll + + + + + False + lib\System.Reactive.dll + + + False + lib\System.Text.Json.dll + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + + + + + + \ No newline at end of file