我正在尝试使用适用于.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的编码问题。
但那可能是猜测。有人遇到过类似的问题吗?
关心马丁
答案 0 :(得分:1)
我通过Twitter与AWS SDK for .NET团队交换了一些消息,他们发现了一个错误。此问题已在SDK的2.0.6.1版中得到解决,现在可在Nuget中使用。