hugo4715
hugo4715

Reputation: 105

Laravel s3 filesystem driver not using AWS_URL variable

I am trying to upload a file to an s3 compatible object storage (I'm using Minio) but the aws client in laravel doesn't use the url I provided in my .env AWS_URL variable.

AWS_URL=http://192.168.1.22:9000

I am using the artisan built-in server and I already tried clearing the config cache.

My current code is:

$request->videoFile->store('videoFiles', 's3');

I'm getting an error which shows that laravel is trying to connect to the wrong url.

Error executing "PutObject" on "https://myawesomebucket.s3.amazonaws.com/videoFiles/bs20uHPxkprbG6fC6e1B6pHtBiQxwgTmrrDdGP2e.mp4"; 

Upvotes: 6

Views: 18895

Answers (2)

AlbinoDrought
AlbinoDrought

Reputation: 1384

The default s3 entry in filesystems.php looks like this:

    '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'),
    ],

Although this seems to have worked with minio at one point, the url property now seems to be ignored completely.

Here is a modified config that works with both minio and S3:

    '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'),

        // the below 'endpoint' url is actually used:
        'endpoint' => env('AWS_URL'),
        // prevent bucket name from being added to the hostname:
        'bucket_endpoint' => false,
        // use older urls:
        'use_path_style_endpoint' => true,
    ],

I referenced these guides to find this information:

Upvotes: 21

ajw4sk
ajw4sk

Reputation: 105

I've had issues with the env file sometimes. I'm not sure if there's enough info here for me to answer your question, but I'd start by dd(AWS_URL) and seeing what actually comes out there. Maybe putting quotes around

AWS_URL="http://192.168.1.22:9000"

If that doesn't work, I've added stuff into the config file:

'url' => 'http://192.168.1.22:9000'

Upvotes: 0

Related Questions