php SignatureDoesNotMatch - Amazon S3 API

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10281557/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 21:48:55  来源:igfitidea点击:

SignatureDoesNotMatch - Amazon S3 API

phpfile-uploaduploadamazon-s3amazon

提问by Roman Nazarkin

I am using a PHP class for Amazon S3 and CloudFront - Link. But when I try to upload a file into a bucket, I get this error:

我正在为 Amazon S3 和 CloudFront - Link使用 PHP 类。但是当我尝试将文件上传到存储桶时,出现此错误:

[SignatureDoesNotMatch] The request signature we calculated does not match the signature you provided. Check your key and signing method.

[SignatureDoesNotMatch] 我们计算的请求签名与您提供的签名不匹配。检查您的密钥和签名方法。

How to fix it?

如何解决?

Thanks.

谢谢。

回答by awendt

When you sign up for Amazon, you can create yourself a key pair (Amazon calls those access key ID and secret access key).

当您注册 Amazon 时,您可以为自己创建一个密钥对(Amazon 称这些为访问密钥 ID 和秘密访问密钥)。

Those two are used to sign requests to Amazon's webservices. Amazon re-calculates the signature and compares if it matches the one that was contained in your request. That way the secret access key never needs to be transmitted over the network.

这两个用于签署对亚马逊网络服务的请求。亚马逊重新计算签名并比较它是否与您的请求中包含的签名相匹配。这样,秘密访问密钥永远不需要通过网络传输。

If you get "Signature does not match", it's highly likely you used a wrong secret access key. Can you double-check access key and secret access key to make sure they're correct?

如果您收到“签名不匹配”,很可能您使用了错误的秘密访问密钥。您可以仔细检查访问密钥和秘密访问密钥以确保它们正确吗?

回答by Carlton

Personally I received this error because of the characters that were in my meta data.

我个人收到这个错误是因为我的元数据中的字符。

The problematic character was the "–" chracter which is "\u2013" in unicode and different to "-".

有问题的字符是“-”字符,它在 unicode 中是“\u2013”​​,与“-”不同。

$result = $s3->putObject(array(
    'Bucket'       => $bucket,
    'Key'          => $keyname,
    'Metadata' => [
        'name' => 'Terminology – Blah'
    ]
));

A note from the documentation http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html#UserMetadata...

来自文档http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html#UserMetadata 的注释 ...

Amazon S3 stores user-defined metadata in lowercase. Each name, value pair must conform to US-ASCII when using REST and UTF-8 when using SOAP or browser-based uploads via POST.

Amazon S3 以小写形式存储用户定义的元数据。使用 REST 时,每个名称、值对都必须符合 US-ASCII,使用 SOAP 或基于浏览器的通过 POST 上传时,必须符合 UTF-8。

回答by Justin Emery

I had this error with putObject()when specifying a Keystarting with slash character (/) - after removing the slash it worked fine.

putObject()指定Key以斜杠字符 ( /)开头时出现此错误- 删除斜杠后它工作正常。