如何生成我的要求签名使用.NET API AWS的S3上传? [英] How do I generate my request signature for AWS S3 uploads using the .NET API?

查看:165
本文介绍了如何生成我的要求签名使用.NET API AWS的S3上传?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是.NET API直接从亚马逊的一些文件上传到S3。

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.

我的code是如下:

    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?

该ProcessFiles方法只返回该目录中的文件名列表。

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

推荐答案

确实 ProcessFiles 返回刚才的文件名或完整的路径?无论如何,这是不可能的文件路径应设置为同样的事情。

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.

文件路径应设置为本地文件上传的完整路径。例如, C:\开发\ pktest \ myfile.txt的

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

是存储在S3上的文件的名称。例如,的myfile.txt 。或者,如果你想保留相同的路径结构:开发/ 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)

这篇关于如何生成我的要求签名使用.NET API AWS的S3上传?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆