I’m simply trying to upload anything on my AWS s3 bucket.
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
'endpoint' => env('AWS_ENDPOINT'),
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
'throw' => false,
],
my .env file contains every necessery keys and infos. I followed many tutorials, all doing the same things, that I did, multiple time.
The steps are as follow:
Create an IAM user, with s3FullAccess permissions.
Generate access keys.
Create bucket. Followed https://laravel-news.com/using-aws-s3-for-laravel-storage instruction to the letter (minimal security on the bucket for testing purposes)
filled the .env file with IAM user keys, bucket region, bucket name
Used a upload input first, validated in the controller to be uploaded.
Currently using a more direct approach:
Route::get('/', function () {
try {
$result = Storage::disk('s3')->put('test.txt', 'This is a test file.');
dd($result);
} catch (Exception $e) {
Log::error('S3 Upload Error: ' . $e->getMessage()); }
});```
the dd always return false. So did the upload input of previous aproach. Tried many buckets, many regions, many users. Always false.
I might be the only morron not capable of making it work, since the steps are not that complicated, and I can't find much on google.
Using PhP 8.3, last version of Laravel (breeze and typescript). Local devellopment (php artisan serve).
It was a tricky one.
While trying to create the bucket through s3 client (I was desperate…):
$s3 = new S3Client([
'version' => 'latest',
'region' => env('AWS_DEFAULT_REGION'),
'credentials' => [
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
]
]);
if (!$s3->doesBucketExist(env('AWS_BUCKET'))) {
// Create bucket if it doesn't exist
try{
$s3->createBucket([
'Bucket' => env('AWS_BUCKET'),
]);
} catch (Exception $e) {
return response()->json([
'Bucket Creation Failed' => $e->getMessage()
]);
}
}
I got
{"Bucket Creation Failed":"Error executing "CreateBucket" on "https://helenebucketparis.s3.eu-west-3.amazonaws.com/"; AWS HTTP error: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://helenebucketparis.s3.eu-west-3.amazonaws.com/"}
So I had to:
- download the cacert.pem from https://curl.se/docs/caextract.html
- go to my php.ini file (in the PHP folder) and modify the line:
- curl.cainfo = “C:pathtoyourcacert.pem”
Everything works now. If that can help someone one day.