C# AWS.NETSDK非法密钥
我正在使用Amazon连接到Amazon的S3 PutObjectRequest的WithKey()方法会自动对抛出的任何字符串进行编码,但仍有一些模式无法处理。不处理密钥意味着抛出以下错误:C# AWS.NETSDK非法密钥,c#,asp.net-mvc-3,amazon-s3,C#,Asp.net Mvc 3,Amazon S3,我正在使用Amazon连接到Amazon的S3 PutObjectRequest的WithKey()方法会自动对抛出的任何字符串进行编码,但仍有一些模式无法处理。不处理密钥意味着抛出以下错误: Amazon.S3.AmazonS3Exception: The request signature we calculated does not match the signature you provided 我从Amazon上几乎找不到关于合法密钥的文档。在S3键中使用哪些模式并引发此异常是非法
Amazon.S3.AmazonS3Exception: The request signature we calculated
does not match the signature you provided
我从Amazon上几乎找不到关于合法密钥的文档。在S3键中使用哪些模式并引发此异常是非法的?我创建了一个方法,在上载到时规范化斜杠键
private static string NormalizeKey(string relativePath)
{
return relativePath.Replace("~/", "").Replace(@"~\", "").Replace(@"\", @"/").Replace(@"//", @"/");
}
关于。我创建了一个方法,在上传到时规范化斜杠键
private static string NormalizeKey(string relativePath)
{
return relativePath.Replace("~/", "").Replace(@"~\", "").Replace(@"\", @"/").Replace(@"//", @"/");
}
关于。在我的特殊情况下,问题有两个方面:
// Cleans a piece of a key - a folder name or final object name:
// - replaces illegal characters with valid ones
// - avoids accidental folder creation by removing slashes inside the key
private string CleanPartialKey(string partialKey)
{
return partialKey.Replace('/', '-') // Add slashes separately - avoid creating accidental folders
.Replace('\\', '_'); // Amazon knows not how to deal with backslashes, so replace them with something else
}
// Ensures a full key does not have any illegal patterns.
// This should only be called with a complete key
private string CleanKey(string fullKey)
{
return fullKey.Replace("./", "/"); // ending a folder with a period is illegal
}
在我的特殊情况下,问题有两个方面:
// Cleans a piece of a key - a folder name or final object name:
// - replaces illegal characters with valid ones
// - avoids accidental folder creation by removing slashes inside the key
private string CleanPartialKey(string partialKey)
{
return partialKey.Replace('/', '-') // Add slashes separately - avoid creating accidental folders
.Replace('\\', '_'); // Amazon knows not how to deal with backslashes, so replace them with something else
}
// Ensures a full key does not have any illegal patterns.
// This should only be called with a complete key
private string CleanKey(string fullKey)
{
return fullKey.Replace("./", "/"); // ending a folder with a period is illegal
}
谢谢Shoaib!我有一个类似的方法来避免在构建密钥时意外创建文件夹。在Replace调用中,波浪号“~”的作用是什么?在我的代码中使用~是因为我设置了相对路径,就像它们存在于我的本地项目中一样。对你来说,这是可以避免的。谢谢你!我有一个类似的方法来避免在构建密钥时意外创建文件夹。在Replace调用中,波浪号“~”的作用是什么?在我的代码中使用~是因为我设置了相对路径,就像它们存在于我的本地项目中一样。在你的情况下,这是可以避免的。