【发布时间】:2020-01-31 03:39:58
【问题描述】:
每次我尝试使用 sdk 将文件上传到我的 s3 存储桶时,我都会不断收到错误消息(AWS HTTP 错误:cURL 错误 6)。我不知道为什么会发生这种情况,也不知道如何解决它。还有什么我需要添加到我的代码或指定的吗?问题只是存储桶还是我创建的用户(IAM)。我不需要明确的答案,我只需要一些可以缩小我需要寻找错误原因的区域的东西。我很乐意感谢任何回应。谢谢。
这是我的代码:
<?php
require 'vendor/autoload.php';
use Aws\S3\S3Client;
// Instantiate an Amazon S3 client.
$s3 = new S3Client([
'version' => 'latest',
'region' => 'US-West',
'credentials' => [
'key' => 'garbage',
'secret' => 'garbage'
]
]);
$bucketName = 'garbage';
$file_Path = __DIR__ . '/my-image.png';
$key = basename($file_Path);
// Upload a publicly accessible file. The file size and type are determined by the SDK.
try {
$result = $s3->putObject([
'Bucket' => $bucketName,
'Key' => 'videouploads/' . $key,
'Body' => fopen($file_Path, 'r'),
'ACL' => 'public-read',
]);
echo $result->get('ObjectURL');
} catch (Aws\S3\Exception\S3Exception $e) {
echo "There was an error uploading the file.\n";
echo $e->getMessage();
}
?>
【问题讨论】:
-
我认为您应该检查您所在的地区。请参阅docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
标签: php amazon-web-services amazon-s3 sdk