C# 通过S3 给minio上上传数据

class OSSAmazonToolsCSharp
    {
       static private string accessKey = "RPW421T9GSIO4A45Y9ZR";
       static private string secretKey = "2owKYy9emSS90Q0pXuyqpX1OxBCyEDYodsiBemcq";
       static private AmazonS3Config config = new AmazonS3Config();
       static private AmazonS3Client s3Client = null;
       static public void init()
       {
          config.ServiceURL = "http://10.1.3.148:9000";
          config.UseHttp = true;//关键配置
          config.ForcePathStyle = true; //关键配置
          s3Client = new AmazonS3Client(accessKey,secretKey,config);
       }
       static public void uploadfile(string bucketname,string osskey,string pathkey)
       {
     
            if (null == s3Client)
            {
                 init();
             }
            PutObjectRequest obj = new PutObjectRequest();
            var fileStream = new FileStream(pathkey, FileMode.Open, FileAccess.Read);
            obj.InputStream = fileStream;
            obj.BucketName = bucketname;
            obj.Key = osskey;
            obj.CannedACL = S3CannedACL.PublicRead;
            PutObjectResponse response = s3Client.PutObject(obj);
            Console.WriteLine(response.ToString()); 
        }
       
       
    }

上面两个关键指定了提交URL的风格

你可能感兴趣的:(C#)