2

有谁知道如何使用 s3 net API 添加自定义端点?
详情:<a href="https://github.com/aws/aws-sdk-net/issues/1283" rel="nofollow noreferrer">https://github.com/aws/aws-sdk-net/问题/1283 代码语言:C#

sServiceUrl 值="192.168.199.216:7480"

当我调用 DoesS3BucketExist 函数时,我修改了一个异常(System.UriFormatException)</p>

这是我的代码

        public IAmazonS3 CreateClient(string sAccessKeyId, string sAccessKeySecret, string sServiceUrl)
        {
            AmazonS3Client s3Client = null;
            try
            {
                AmazonS3Config config = new AmazonS3Config();
                config.ServiceURL = sServiceUrl;
                config.UseHttp = false;
                config.SignatureVersion = "v4";
                AWSConfigsS3.UseSignatureVersion4 = true;

                s3Client = new AmazonS3Client(
                        sAccessKeyId,
                        sAccessKeySecret,
                        config
                        );
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("AWS配置", ex, "创建AmazonS3Client失败!");
            }
            return s3Client;
        }

public bool DoesBucketExist(string bucketName)
{
    bool bIsExist;
    if (this.Client != null)
    {
        bIsExist = this.Client.DoesS3BucketExist(bucketName);
    }
    else
    {
        bIsExist = false;
    }
    return bIsExist;
}

我想设置这个属性AWSConfigs.EndpointDefinition = @"c:pathtoendpoints.xml";,但我不知道如何自定义 endpoints.json 文件。

这对我来说太难了,也许我需要上帝帮助我!任何帮助将不胜感激!

4

1 回答 1

3
static void Main(string[] args)
    {
        string accessKey = "";
        string secretKey = "";

        AmazonS3Config config = new AmazonS3Config()
        {
            ServiceURL = string.Format("http://{0}", "192.168.199.216:7480"),
            UseHttp = true,
            ForcePathStyle = true,
            ProxyHost = "192.168.199.216",
            ProxyPort = 7480
        };

        AWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey);
        AmazonS3Client s3Client = new AmazonS3Client(creds, config);
        try
        {
            ListBucketsResponse response = s3Client.ListBuckets();
            foreach (S3Bucket b in response.Buckets)
            {
                Console.WriteLine("{0}\t{1}", b.BucketName, b.CreationDate);
            }
        }
        catch (Exception ex)
        {

            throw;
        }
于 2019-05-08T10:22:46.673 回答