using Amazon; using Amazon.Runtime; using Amazon.S3; using System; using S3Demo.Storage; using S3Demo.Model; using System.Threading.Tasks; namespace S3Demo { public class Run { private static BasicAWSCredentials credentials = new BasicAWSCredentials("admin", "admin123."); private static string bucketName = "minio/test"; /// /// https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/S3/TS3Config.html /// https://blog.csdn.net/tw_tangliang/article/details/118669099 /// https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/dotnetv3/S3/UploadFileMPUHighLevelAPIExample/UploadFileMPUHighLevelAPIExample/UploadFileMPUHighLevelAPI.cs /// private static AmazonS3Config conf = new AmazonS3Config() { UseHttp = true, ProxyHost = "http://192.168.60.132", ProxyPort = 9000, RegionEndpoint = RegionEndpoint.USEast1 }; public static async Task Main() { try { //creating Bucket //await CreateBucket.CreatingBucket("minio/bu29", credentials, conf); //upload Dir string dirPath = @"C:\Users\song\Pictures\Saved Pictures\"; string suffix = "*.png"; //await UploadDirMPUHighLevelAPI.Uploaderdir(bucketName, dirPath, suffix, credentials, conf); //upload File string keyName = "logo.png"; //await UploadFileMPUHighLevelAPI.Uploaderfile(bucketName, keyName, dirPath, credentials, conf); //list Objects //await ListObjects.Listingobjects(bucketName, credentials, conf); //upload Object With Tag string filaPath = @"C:\Users\song\Pictures\Saved Pictures\" + keyName; String[] tags = new String[] { "SN123456", DateTime.Now.ToString("yyyy-MM-dd'T'HH:mm:sszzz"), "AB023" }; //await ObjectModel.Putobjectswithtags(bucketName, keyName, filaPath, tags, credentials, conf); //read Object //await ObjectModel.Readobjectdata(bucketName, keyName, credentials, conf); //isExist Bucket //从"minio/test"中取出存储桶名 var _bucketName = bucketName.Split('/')[1]; //此处传入bucketName: "test" var flag = await BucketModel.isExistBucket(_bucketName, credentials, conf); if (flag) { Console.WriteLine("exist"); } else { Console.WriteLine("not exist"); //此处传入BucketName: "minio/test" await BucketModel.CreateBucket(bucketName, credentials, conf); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } Console.ReadKey(); } } }