You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.7 KiB
74 lines
2.7 KiB
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";
|
|
|
|
/// <summary>
|
|
/// 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
|
|
/// </summary>
|
|
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
|
|
{
|
|
//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];
|
|
var flag = await BucketModel.isExistBucket(_bucketName, credentials, conf);
|
|
if (flag)
|
|
{
|
|
Console.WriteLine("exist");
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("not exist");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.ToString());
|
|
}
|
|
|
|
Console.ReadKey();
|
|
}
|
|
}
|
|
}
|