在softlayer对象存储中获取错误SignatureDoesNotMatch .NET

时间:2017-06-22 19:55:49

标签: ibm-cloud-infrastructure

当我通过https将图像加载到对象存储软件层中的存储桶时,出现错误:

  

我们计算的请求签名与您的签名不符   提供。检查您的AWS秘密访问密钥和签名方法

任何人都可以帮忙吗?

var accessKeyId = <accessKeyId>
var secretAccessKey = <secretAccessKey>
AmazonS3Config S3Config = new AmazonS3Config
     {
          ServiceURL = <https:serviceUrl>,
          MaxErrorRetry = 0
      };
BasicAWSCredentials credentials = new 
          BasicAWSCredentials(accessKeyId, secretAccessKey);
AmazonS3Client client = new AmazonS3Client(credentials, S3Config);
var bucketName = "my-bucket";
PutObjectRequest putRequest = new PutObjectRequest
      {
          BucketName = bucketName,
          Key ="item1", //key,
          ContentBody = "test",
          ContentType ="application/text"
       };
PutObjectResponse response = client.PutObject(putRequest);

1 个答案:

答案 0 :(得分:0)

您正在使用的代码正在运行,我能够将&#34; item1&#34; 发送到我的存储桶。我第一次收到错误&#34;权限被拒绝&#34;,这是因为 bucketName ServiceURL 是错误的,例如,bucketName没有&#t; t存在于ServiceURL中。

我认为问题可能是您正在使用的 accessKeyId secretAccessKey ,以防万一我建议您查看IBM Cloud Object Storage - S3 API Intro,该页面会显示如何获取您订购的对象存储的 accessKeyId secretAccessKey

其他问题可能是您要发送的标题,根据API reference&#34; x-amz-content-sha256&#34; 是上传对象所必需的。想法是添加以下行代码:

putRequest.Headers["x-amz-content-sha256"] = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"

可以使用sha256-hash-calculator

等工具生成 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 的值

我希望这对你有所帮助。

参考文献:

https://ibm-public-cos.github.io/crs-docs/api-reference

https://ibm-public-cos.github.io/crs-docs/about-compatibility-api

https://developer.ibm.com/recipes/tutorials/cloud-object-storage-s3-api-intro/

https://aws.amazon.com/sdk-for-net/

http://docs.aws.amazon.com/AmazonS3/latest/dev/RetrievingObjectUsingNetSDK.html