简体   繁体   中英

How do I generate my request signature for AWS S3 uploads using the .NET API?

I'm using the .NET API straight from Amazon to upload some files to S3.

However, I'm getting the exception message: The request signature we calculated does not match the signature you provided. Check your key and signing method. The request signature we calculated does not match the signature you provided. Check your key and signing method.

My code is as follows:

    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();

Is there anything immediately obvious I'm doing wrong?

The ProcessFiles method just returns a list of filenames in that directory.

Does ProcessFiles return just the filename or the complete path? Regardless, it's unlikely that FilePath and Key should be set to the same thing.

FilePath should be set to the full path of the local file to upload. eg c:\\Dev\\pktest\\myfile.txt

Key is the name of the file to store on S3. eg myfile.txt . Or if you want keep the same path structure: Dev/pktest/myfile.txt (note the forward slashes)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM