<p>我已经在网上搜索了两天多,并且可能已经浏览了大多数在线记录的场景和解决方法,但到目前为止没有任何效果。<br />
我使用的是在 PHP 5.3 上运行的适用于 PHP V2.8.7 的 Amazon 开发工具包。<br />
我正在尝试使用以下代码连接到我的 Amazon S3 存储桶:<br />
// Create a <code>Aws</code> object using a configuration file<br />
$aws = Aws::factory(‘config.php’);</p>
<p>// Get the client from the service locator by namespace<br />
$s3Client = $aws->get(‘s3’);</p>
<p><span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>b</mi><mi>u</mi><mi>c</mi><mi>k</mi><mi>e</mi><mi>t</mi><mo>=</mo><mi mathvariant="normal">"</mi><mi>x</mi><mi>x</mi><mi>x</mi><mi mathvariant="normal">"</mi><mo separator="true">;</mo></mrow><annotation encoding="application/x-tex">bucket = "xxx";
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.69444em;"></span><span class="strut bottom" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="base"><span class="mord mathit">b</span><span class="mord mathit">u</span><span class="mord mathit">c</span><span class="mord mathit" style="margin-right:0.03148em;">k</span><span class="mord mathit">e</span><span class="mord mathit">t</span><span class="mrel">=</span><span class="mord mathrm">"</span><span class="mord mathit">x</span><span class="mord mathit">x</span><span class="mord mathit">x</span><span class="mord mathrm">"</span><span class="mpunct">;</span></span></span></span>keyname = “xxx”;</p>
<p>try {<br />
$result = $s3Client->putObject(array(<br />
‘Bucket’ => $bucket,<br />
‘Key’ => $keyname,<br />
‘Body’ => ‘Hello World!’<br />
));</p>
<pre><code>$file_error = false;
</code></pre>
<p>} catch (Exception $e) {<br />
$file_error = true;</p>
<pre><code>echo $e->getMessage();
die();
</code></pre>
<p>}<br />
My config.php file is as follows:<br />
return [<br />
// Bootstrap the configuration file with AWS specific features<br />
‘includes’ => [’_aws’],<br />
‘services’ => [<br />
// All AWS clients extend from ‘default_settings’. Here we are<br />
// overriding ‘default_settings’ with our default credentials and<br />
// providing a default region setting.<br />
‘default_settings’ => [<br />
‘params’ => [<br />
‘credentials’ => [<br />
‘key’ => ‘key’,<br />
‘secret’ => ‘secret’<br />
]<br />
]<br />
]<br />
]<br />
];<br />
它产生以下错误:<br />
我们计算的请求签名与您提供的签名不匹配。检查您的密钥和签名方法。<br />
我已经检查了我的访问密钥和密码至少20次,并且生成了新的,也使用了不同的方法传递信息(即配置文件和在代码中包含凭据),但目前没有任何效果。</p>
<p>经过两天的调试,我终于发现了问题。。。<br />
我分配给对象的键以句点开头,即 …\images\ABC.jpg,这导致错误发生。<br />
我希望 API 提供更有意义和相关的错误消息,唉,我希望这能帮助其他人!</p>