gpt4 book ai didi

c# - AWS Glacier 上传 InvalidSignatureException C#

转载 作者:太空宇宙 更新时间:2023-11-03 13:30:19 26 4
gpt4 key购买 nike

我正在试用适用于 .NET 的 AWS 开发工具包,但遇到了以下问题。我无法使上传工作。

我想做的是:

class ArchiveUploadSingleOpLowLevel
{
static string vaultName = "test001";
static string archiveToUpload = "ver.txt"; //located in the same directory as the executable

public static void Upload()
{
AmazonGlacierClient client;
try
{
using (client = new AmazonGlacierClient(Amazon.RegionEndpoint.EUWest1))
{
Console.WriteLine("Uploading an archive.");
string archiveId = UploadAnArchive(client);
Console.WriteLine("Archive ID: {0}", archiveId);
}
Console.WriteLine("To continue, press Enter");
Console.ReadKey();
}
catch (AmazonGlacierException e) { Console.WriteLine(e.Message); }
catch (AmazonServiceException e) { Console.WriteLine(e.Message); }
catch (Exception e) { Console.WriteLine(e.Message); }
Console.WriteLine("To continue, press Enter");
Console.ReadKey();
}

static string UploadAnArchive(AmazonGlacierClient client)
{
using (FileStream fileStream = new FileStream(archiveToUpload, FileMode.Open, FileAccess.Read))
{
string treeHash = TreeHashGenerator.CalculateTreeHash(fileStream);
UploadArchiveRequest request = new UploadArchiveRequest()
{
VaultName = vaultName,
Body = fileStream,
Checksum = treeHash
};
UploadArchiveResponse response = client.UploadArchive(request);
string archiveID = response.ArchiveId;
return archiveID;
}
}
}

但我不断得到的结果是这个 AmazonGlacierException:

InvalidSignatureException

The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.

The Canonical String for this request should have been
'POST
/-/vaults/test001/archives

content-type:binary/octet-stream
host:glacier.eu-west-1.amazonaws.com
user-agent:aws-sdk-dotnet-45/2.0.4.0 .NET Runtime/4.0 .NET Framework/4.0 OS/6.2.9200.0
x-amz-content-sha256:2a7087861fb29e1f77da3600df98a9d3b0d1e8dee8d65700a6f2a5599c5a50ae, 2a7087861fb29e1f77da3600df98a9d3b0d1e8dee8d65700a6f2a5599c5a50ae
x-amz-date:20131230T114010Z
x-amz-glacier-version:2012-06-01
x-amz-sha256-tree-hash:2a7087861fb29e1f77da3600df98a9d3b0d1e8dee8d65700a6f2a5599c5a50ae
x-amz-target:Glacier.UploadArchive

content-type;host;user-agent;x-amz-content-sha256;x-amz-date;x-amz-glacier-version;x-amz-sha256-tree-hash;x-amz-target
2a7087861fb29e1f77da3600df98a9d3b0d1e8dee8d65700a6f2a5599c5a50ae, 2a7087861fb29e1f77da3600df98a9d3b0d1e8dee8d65700a6f2a5599c5a50ae'

The String-to-Sign should have been
'AWS4-HMAC-SHA256
20131230T114010Z
20131230/eu-west-1/glacier/aws4_request
d405bac6780608e6fc3f7091dc5a9aa1d4d0d8415d61732feba6b9970678d40f'

现在明显的错误是我的配置中有错误的 AWSAccessKey 或 AWSSecretKey。我一遍又一遍地检查并重新复制/粘贴它们。文档和高级 API 没有提供太多关于签名方法的信息。

此外,我已在同一个应用程序中成功创建并列出了我的保管库。

因此,由于我在 win8.1(英文版)上运行 .Net 4.5、VS2012 SP3,因此我倾向于连接 TreeHashGenerator 的编码问题。

但这只是猜测。有人遇到过类似的问题吗?

问候马丁

最佳答案

我通过 Twitter 与 AWS SDK for .NET 团队交换了一些消息,他们发现了一个错误。此问题已在 SDK 2.0.6.1 版本中得到解决,现在可在 Nuget 中使用。

关于c# - AWS Glacier 上传 InvalidSignatureException C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20839361/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com