Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"; 
like image 951
hugo4715 Avatar asked Dec 08 '22 12:12

hugo4715


1 Answers

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:

  • https://laravel.com/docs/5.8/homestead (under the "Configuring Minio" header)
  • https://github.com/minio/docs/blob/c599f9da365cfc4c5b9d4c44fa58ff09a3bcee59/docs/how-to-use-minio-as-laravel-file-storage.md
like image 111
AlbinoDrought Avatar answered Dec 20 '22 04:12

AlbinoDrought