[英]AWS .NET SDK illegal keys
我正在使用Amazon的AWS .NET SDK連接到Amazon的S3。
PutObjectRequest的WithKey()方法會自動對您向其拋出的任何字符串進行編碼,但是仍然存在一些無法處理的模式。 不處理鍵意味着拋出以下錯誤:
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(@"//", @"/");
}
問候。
在我的特定情況下,問題有兩個:
我編寫了以下兩種方法來構建密鑰:
// 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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.