2011-04-01 100 views
2

我使用直接從亞馬遜的.NET API上傳一些文件到S3。如何使用.NET API爲AWS S3上傳生成我的請求籤名?

但是,我得到異常消息:The request signature we calculated does not match the signature you provided. Check your key and signing method.

我的代碼如下:

AmazonS3 s3Client = AWSClientFactory.CreateAmazonS3Client("myaccessid","mysecretid"); 
    List<string> allFileNames = ProcessFiles(@"c:\Dev\pktest\"); 
    foreach (string file in allFileNames) 
    {     

     PutObjectRequest putObjectRequest = new PutObjectRequest 
     { 
      BucketName = "rhspktest", 
      FilePath = file, 
      Key = file, 
      Timeout = 3600000      
     }; 

     try 
     { 
      using (S3Response response = s3Client.PutObject(putObjectRequest)) { }; 
     } 
     catch (AmazonS3Exception ex) 
     { 
      Console.WriteLine(ex.Message); 
     } 

      Console.WriteLine(file); 

     } 
     Console.Read(); 

有什麼立竿見影我做錯了嗎?

ProcessFiles方法只是返回該目錄中的文件名列表。

回答

11

ProcessFiles是否只返回文件名或完整路徑?無論如何,FilePathKey應該被設置爲相同的東西。

FilePath應該設置爲要上傳的本地文件的完整路徑。例如c:\Dev\pktest\myfile.txt

Key是存儲在S3上的文件的名稱。例如myfile.txt。或者如果你想保持相同的路徑結構:Dev/pktest/myfile.txt(注意正斜槓)

+1

是的,你是對的。我認爲這是造成這個問題的反斜槓。 – 2011-04-03 11:00:23

相關問題