Closed marlongichie closed 5 years ago
Have you cached your configuration?
Does dd(config('filesystems.disks.s3.region'));
show the correct value?
@staudenmeir No. dd(config('filesystems.disks.s3.region'));
returns null
See below output of dd(config('filesystems.disks.s3'));
array:6 [▼
"driver" => "s3"
"key" => null
"secret" => null
"region" => null
"bucket" => null
"url" => null
]
What does your config/filesystems.php
file look like?
I'm using the default config/filesystems.php
. See below:
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Filesystem Disk
|--------------------------------------------------------------------------
|
| Here you may specify the default filesystem disk that should be used
| by the framework. The "local" disk, as well as a variety of cloud
| based disks are available to your application. Just store away!
|
*/
'default' => env('FILESYSTEM_DRIVER', 'local'),
/*
|--------------------------------------------------------------------------
| Default Cloud Filesystem Disk
|--------------------------------------------------------------------------
|
| Many applications store files both locally and in the cloud. For this
| reason, you may specify a default "cloud" driver here. This driver
| will be bound as the Cloud disk implementation in the container.
|
*/
'cloud' => env('FILESYSTEM_CLOUD', 's3'),
/*
|--------------------------------------------------------------------------
| Filesystem Disks
|--------------------------------------------------------------------------
|
| Here you may configure as many filesystem "disks" as you wish, and you
| may even configure multiple disks of the same driver. Defaults have
| been setup for each driver as an example of the required options.
|
| Supported Drivers: "local", "ftp", "sftp", "s3", "rackspace"
|
*/
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
'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'),
],
],
];
Are your environment variables configured in the .env
file?
What does dd(env('AWS_DEFAULT_REGION'));
show you?
Snippet from .env
file below
APP_NAME="My App Name"
FILESYSTEM_DRIVER=s3 FILESYSTEM_CLOUD=s3
AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXX AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx AWS_DEFAULT_REGION=us-east-2 AWS_BUCKET=bucketname AWS_URL=https://apigateway.us-east-2.amazonaws.com
dd(env('AWS_DEFAULT_REGION'))
returns null
dd()
for all variables associated with FILESYSTEM & AWS returns null
However other env variables return expected values:
dd(env('APP_NAME'))
returns My App Name
also dd(config('app.name'))
returns My App Name
Can you reproduce this on a fresh installation of Laravel?
Did a fresh install of Laravel just now.
Configured the following:
FILESYSTEM_DRIVER=s3
FILESYSTEM_CLOUD=s3
AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXX
AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
AWS_DEFAULT_REGION=us-east-2
AWS_BUCKET=bucketname
AWS_URL=https://apigateway.us-east-2.amazonaws.com
See below output of dd(config('filesystems.disks.s3'))
array:6 [▼
"driver" => "s3"
"key" => ""
"secret" => ""
"region" => "us-east-1"
"bucket" => ""
"url" => "https://apigateway.us-east-2.amazonaws.com"
]
Output from dd(env('AWS_DEFAULT_REGION'))
is "us-east-1"
Looks like there is a default region that is overwriting the value I set in the .env
file. Also, the other values return an empty string in this case.
Strange behavior. Your thoughts?
I was able to solve this in my existing project. It seems there was a missing closing quote in the .env
file before the FILESYSTEM_ variables which affected everything that came after it.
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER <--missing closing quote
FILESYSTEM_DRIVER=s3
FILESYSTEM_CLOUD=s3
...
But, I'm not sure what issue was causing the variable to be overwritten in the fresh Laravel install project.
Thanks @staudenmeir .
Regarding the fresh installation: The sample .env
file already contains default values for AWS_DEFAULT_REGION
and others. Did you remove/replace those?
You're absolutely right @staudenmeir .
Looks to be configuration error rather than an issue with Laravel itself. I think it's fair to close this out at this point.
Thank you again for helping with this issue.
Best.
Please close the issue.
I know this is closed. i had same issue and different problem. I had copied the .env AWS configuration from one Laravel version to another version. Turns out the config/filesystem AWS variables were different from each Laravel version One version used AWS_DEFAULT_REGION= and Other used AWS_REGION=
For reference my fix was to run php artisan config:cache
, which wiped the current version of my .env cache and replaced it with the live values.
if php artisan config:clear
doesnt work.
It can be that you already have media in your database that points to s3, and when retrieve it tries to resolve the url.
When you don't already have the s3 credentials or commented it out in .env
because you switch to another disk, you will get that error.
I encountered that error using spatie/laravel-medialibrary
if
php artisan config:clear
doesnt work.It can be that you already have media in your database that points to s3, and when retrieve it tries to resolve the url. When you don't already have the s3 credentials or commented it out in
.env
because you switch to another disk, you will get that error.I encountered that error using
spatie/laravel-medialibrary
Hi Jessie,
I'm using the spatie/laravel-medialibrary
and I got the error when hosting the app on Laravel Forge. Checked every config from tinker and looks correct to me but getting missing configuration error regardless, which local is totally fine. Wondering how do you solve this problem? If there's something in DB point to S3, what tables I should check? Thank you.
if
php artisan config:clear
doesnt work. It can be that you already have media in your database that points to s3, and when retrieve it tries to resolve the url. When you don't already have the s3 credentials or commented it out in.env
because you switch to another disk, you will get that error. I encountered that error usingspatie/laravel-medialibrary
Hi Jessie,
I'm using the
spatie/laravel-medialibrary
and I got the error when hosting the app on Laravel Forge. Checked every config from tinker and looks correct to me but getting missing configuration error regardless, which local is totally fine. Wondering how do you solve this problem? If there's something in DB point to S3, what tables I should check? Thank you.
Hey there @Fitmavincent,
I am running into this issue myself, could you solve it?
Description:
When trying to upload files to AWS S3, the following error is reported:
Steps To Reproduce:
Configure environment variables as follows:
Has anyone else come across this issue? Am I missing something?