我是亞馬遜AWS的新手&嘗試使用以下顯示的控制檯應用程序使用SDK for .NET將對象(本例中爲圖像)放入(上載)到存儲桶中:亞馬遜S3和C#簽名不匹配錯誤
namespace AwsConsoleApp1
{
class Program
{
static string bucketName = "bucketName";
static string keyName = "keyName";
static string filePath = "filePath";
static IAmazonS3 client;
public static void Main(string[] args)
{
NameValueCollection appConfig = ConfigurationManager.AppSettings;
string accessKeyID = appConfig["AWSAccessKey"];
string secretAccessKeyID = appConfig["AWSSecretKey"];
try
{
using (client = Amazon.AWSClientFactory.CreateAmazonS3Client(accessKeyID, secretAccessKeyID, Amazon.RegionEndpoint.EUWest1))
{
Console.WriteLine("Uploading an object");
WritingAnObject();
}
}
catch (AmazonS3Exception s3Exception)
{
Console.WriteLine(s3Exception.Message, s3Exception.InnerException);
}
catch (AmazonSecurityTokenServiceException stsException)
{
Console.WriteLine(stsException.Message, stsException.InnerException);
}
}
/// <summary>
/// Put object to AWS bucket
/// </summary>
static void WritingAnObject()
{
try
{
PutObjectRequest putRequest1 = new PutObjectRequest
{
BucketName = bucketName,
Key = keyName,
FilePath = filePath
};
PutObjectResponse response1 = client.PutObject(putRequest1);
}
catch (AmazonS3Exception amazonS3Exception)
{
if (amazonS3Exception.ErrorCode != null &&
(amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId")
||
amazonS3Exception.ErrorCode.Equals("InvalidSecurity")))
{
Console.WriteLine("Check the provided AWS Credentials.");
Console.WriteLine(
"For service sign up go to http://aws.amazon.com/s3");
}
else
{
Console.WriteLine(
"Error occurred. Message:'{0}' when writing an object"
, amazonS3Exception.Message);
}
}
}
}
}
我收到以下錯誤:
The request signature we calculated does not match the signature you provided.Check your key and signin method.
你需要確保你的鑰匙是完全正確的 - 在他們之前或之後沒有額外的空間,並確保沒有額外的引號。 – 2014-09-23 10:14:54
是的,我正好使用這些鍵(我只是交叉檢查了這個)。 – Vikram 2014-09-23 10:19:59