【问题标题】:C# Minio PutBucket Request: A WebException with status NameResolutionFailure was thrownC# Minio PutBucket 请求:抛出状态为 NameResolutionFailure 的 WebException
【发布时间】:2019-09-14 15:50:55
【问题描述】:

我正在开发兼容 Amazon s3 的对象存储解决方案 (Minio)。

我在例如 192.168.235.143:9000 上有一个 Minio 服务器

我试图获取 C# 版本的 Amazon s3 Api 上的存储桶列表。 一切正常。

当我尝试将存储桶放入此服务器时,例如 test1,Visual Studio 将此请求引发异常:

Amazon.Runtime.AmazonServiceException: 
'A WebException with status NameResolutionFailure was thrown.'

WebException: The remote name could not be resolved: 'test1.192.168.235.143'

这是我的代码:

AmazonS3Config config = new AmazonS3Config();
config.ServiceURL = "192.168.235.143:9000";
AmazonS3Client client = new AmazonS3Client(AccessKey, SecretKey, config);
PutBucketRequest request = new PutBucketRequest();
request.BucketName = "test1";
// this Line will throws above exception :
client.PutBucket(request);

ListBuckets 的工作让我感到困惑:

AmazonS3Client client = new AmazonS3Client(AccessKey, SecretKey, config);
var response = client.ListBuckets();
foreach (S3Bucket b in response.Buckets)
{
    MessageBox.Show(string.Format("{0}\t{1}", b.BucketName, b.CreationDate));
}

我已经测试过这个异常的原因:

  1. 我已将它安装在虚拟机和本地版本上,以便仔细检查此问题,但它仍然存在。
  2. 我什至将 Minio 端口更改为 port #80
  3. 我什至用过“play.min.io”但没有区别

我需要使用一个已知接口,以便我们能够移植到另一个对象存储平台,例如 Ceph,...。

我还没有解决问题的想法。

请帮我找出我的错误或更好的解决方案

【问题讨论】:

    标签: c# amazon-s3 object-storage minio


    【解决方案1】:

    在这里我找到了一个示例工作代码,感谢 Minio GitHub 社区:

    using Amazon.S3;
    using System;
    using System.Threading.Tasks;
    using Amazon;
    
    class Program
    {
         private const string accessKey = "PLACE YOUR ACCESS KEY HERE";
         private const string secretKey = "PLACE YOUR SECRET KEY HERE"; // do not store secret key hardcoded in your production source code!
    
         static void Main(string[] args)
         {
             Task.Run(MainAsync).GetAwaiter().GetResult();
         }
    
         private static async Task MainAsync()
         {
             var config = new AmazonS3Config
             {
                 RegionEndpoint = RegionEndpoint.USEast1, // MUST set this before setting ServiceURL and it should match the `MINIO_REGION` enviroment variable.
                 ServiceURL = "http://localhost:9000", // replace http://localhost:9000 with URL of your MinIO server
                 ForcePathStyle = true // MUST be true to work correctly with MinIO server
             };
             var amazonS3Client = new AmazonS3Client(accessKey, secretKey, config); 
    
             // uncomment the following line if you like to troubleshoot communication with S3 storage and implement private void OnAmazonS3Exception(object sender, Amazon.Runtime.ExceptionEventArgs e)
             // amazonS3Client.ExceptionEvent += OnAmazonS3Exception;
    
             var listBucketResponse = await amazonS3Client.ListBucketsAsync();
    
             foreach (var bucket in listBucketResponse.Buckets)
             {
                 Console.Out.WriteLine("bucket '" + bucket.BucketName + "' created at " + bucket.CreationDate);
             }
             if (listBucketResponse.Buckets.Count > 0)
             {
                 var bucketName = listBucketResponse.Buckets[0].BucketName;
    
                 var listObjectsResponse = await amazonS3Client.ListObjectsAsync(bucketName);
    
                 foreach (var obj in listObjectsResponse.S3Objects)
                 {
                     Console.Out.WriteLine("key = '" + obj.Key + "' | size = " + obj.Size + " | tags = '" + obj.ETag + "' | modified = " + obj.LastModified);
                 }
             }
         }
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-26
      • 2013-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多