【发布时间】:2020-01-30 03:46:51
【问题描述】:
我在下面有这段代码,应该将图像上传到我的 s3 存储桶,但我不知道如何告诉它上传到我的 s3 存储桶中的特定文件夹(名为 videouploads)。有人可以帮忙吗?
require 'vendor/autoload.php';
use Aws\S3\S3Client;
// Instantiate an Amazon S3 client.
$s3 = new S3Client([
'version' => 'latest',
'region' => 'grabage',
'credentials' => [
'key' => 'garbage',
'secret' => 'grabage'
]
]);
$bucketName = 'cgrabage';
$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' => $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();
}
【问题讨论】:
-
这能回答你的问题吗? PutObject into directory Amazon s3 / PHP
-
是的,这在某种程度上确实回答了我的问题,但现在我收到了那个错误,指出
an error uploading the file. Error executing "PutObject" on "https://cactustestphp.s3.us west.amazonaws.com/videouploads/my-image.png"; AWS HTTP error: cURL error 3: (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)
标签: php amazon-web-services sdk