开发者

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

开发者 https://www.devze.com 2023-02-21 23:59 出处:网络
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. Ch

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.

My code is as follows:

    AmazonS3 s3Client = AWSClientF开发者_如何学JAVAactory.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)

0

精彩评论

暂无评论...
验证码 换一张
取 消