AWS SDK for .NET。您不提供您提供的授权机制

时间:2022-04-02 23:07:53

I received the next error while sending the ListObjectRequest:

发送ListObjectRequest时收到了下一个错误:

The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256

According to this answer, AmazonS3Config was updated in the following way:

根据这个答案,AmazonS3Config以下列方式更新:

var amazonS3Config = new AmazonS3Config
{
    SignatureVersion = "4",
    ServiceURL = bucketName,
    RegionEndpoint = RegionEndpoint.USEast1,
    SignatureMethod = SigningAlgorithm.HmacSHA256
};

var s3Client = new AmazonS3Client(accessKeyID, secretKey, amazonS3Config);

But I still receive this error. What have I missed here?

但我仍然收到这个错误。我错过了什么?

Thanks.

谢谢。

1 个解决方案

#1


1  

Try to use the last version of amazonS3 sdk.I think ServiceUrl is not necessary when you know regionEndpoint, I used it with private cloud amazonS3 and When I do not know the Region Endpoint. I can retrieve the information from Amazon using the following code.

尝试使用amazonS3 sdk的最新版本。我认为当您知道regionEndpoint时我不需要ServiceUrl,我将它用于私有云amazonS3并且当我不知道Region Endpoint时。我可以使用以下代码从Amazon检索信息。

        var amazonS3Config = new AmazonS3Config();
        // region of FrankPurt is : RegionEndpoint.EUCentral1
        // according to amazonS3 Doc http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
        amazonS3Config.RegionEndpoint = RegionEndpoint.USEast1;

        var s3Client = new AmazonS3Client("your access key", "your secret key", amazonS3Config);
         S3DirectoryInfo dir = new S3DirectoryInfo(s3Client, "your bucket name", "your folder path without bucket name");
        Console.WriteLine(dir.GetFiles().Count());

#1


1  

Try to use the last version of amazonS3 sdk.I think ServiceUrl is not necessary when you know regionEndpoint, I used it with private cloud amazonS3 and When I do not know the Region Endpoint. I can retrieve the information from Amazon using the following code.

尝试使用amazonS3 sdk的最新版本。我认为当您知道regionEndpoint时我不需要ServiceUrl,我将它用于私有云amazonS3并且当我不知道Region Endpoint时。我可以使用以下代码从Amazon检索信息。

        var amazonS3Config = new AmazonS3Config();
        // region of FrankPurt is : RegionEndpoint.EUCentral1
        // according to amazonS3 Doc http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
        amazonS3Config.RegionEndpoint = RegionEndpoint.USEast1;

        var s3Client = new AmazonS3Client("your access key", "your secret key", amazonS3Config);
         S3DirectoryInfo dir = new S3DirectoryInfo(s3Client, "your bucket name", "your folder path without bucket name");
        Console.WriteLine(dir.GetFiles().Count());