Tried to upload file to S3 Bucket, i set up the SDK using the following code:
<?php
use AwsS3S3Client;
use AwsExceptionAwsException;
try {
require 'vendor/autoload.php';
$s3 = new AwsS3S3Client([
'region' => 'us-east-1',
'version' => 'latest',
'credentials' => [
'key' => "KEY",
'secret' => "SECRET",
]
]);
$result = $s3->putObject([
'Bucket' => 'bucketname',
'Key' => 'test.txt',
'SourceFile' => 'test.txt'
]);
var_dump($result);
} catch (Throwable $th) {
echo $th;
}
Error log
AWS HTTP error: Client error: `PUT https://bucketname.s3.amazonaws.com/test.txt` resulted in a `404 Not Found` response: NoSuchBucketThe specified bucket does not exist
Possible errors:
The URL should be this form based on:
Documentation
https://s3.Region.amazonaws.com/bucket-name/key name
question from:
https://stackoverflow.com/questions/65952234/upload-file-to-s3-bucket-with-aws-sdk-nosuchbucket-error 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…