Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel with MinIO on Docker: Unable to Write File When Uploading an Image

I’m working on a Laravel project that uses MinIO as the storage solution. The project is running on Laravel Sail/Docker. However, when I attempt to upload an image, I encounter the following error:

Unable to write file at location: 678d8f3bcfb681737330491.webp. Error executing \"PutObject\" on \"http://127.0.0.1:9000/temporary/678d8f3bcfb681737330491.webp\"; AWS HTTP error: cURL error 7: Failed to connect to 127.0.0.1 port 9000 after 0 ms: Connection refused (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://127.0.0.1:9000/temporary/678d8f3bcfb681737330491.webp

Here are the relevant configurations in my project:

FILESYSTEM_DISK=s3

AWS_ACCESS_KEY_ID=sail
AWS_SECRET_ACCESS_KEY=password
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=spondise
AWS_URL=http://127.0.0.1:9000
AWS_ENDPOINT=http://127.0.0.1:9000
AWS_USE_PATH_STYLE_ENDPOINT=true

Docker Compose Configuration for MinIO:

minio:
    image: 'minio/minio:latest'
    ports:
        - '9000:9000'
        - '8900:8900'
    environment:
        MINIO_ROOT_USER: sail
        MINIO_ROOT_PASSWORD: password
    volumes:
        - 'sail-minio:/data/minio'
    networks:
        - sail
    command: 'minio server /data/minio --console-address ":8900"'
    healthcheck:
        test:
            - CMD
            - curl
            - '-f'
            - 'http://localhost:9000/minio/health/live'
        retries: 3
        timeout: 5s

filesystems.php config (i took only one bucket since i got many buckets but they have the same config)

's3' => [
    'blog' => [
        'driver' => 's3',
        'key' => env('AWS_ACCESS_KEY_ID'),
        'secret' => env('AWS_SECRET_ACCESS_KEY'),
        'region' => env('AWS_DEFAULT_REGION'),
        'bucket' => 'blog',
        'url' => env('AWS_URL') . '/blog',
        'endpoint' => env('AWS_ENDPOINT'),
        'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', true),
        'throw' => true,
    ],
],
like image 727
draw134 Avatar asked Jan 25 '26 21:01

draw134


1 Answers

Since you already mentioned that you can write with AWS_ENDPOINT=http://minio:9000, and you can render files with AWS_ENDPOINT=http://127.0.0.1:9000, then you will have to use a different .env variable.

Use this AWS_URL= variable to properly render files.

Here is my localhost laravel/minio docker setup.

.env →

FILESYSTEM_DISK=s3

AWS_ACCESS_KEY_ID=some_access_key_id
AWS_SECRET_ACCESS_KEY=some_access_key
AWS_DEFAULT_REGION=ap-northeast-1
AWS_BUCKET=default
AWS_USE_PATH_STYLE_ENDPOINT=true
AWS_ENDPOINT=http://minio:9000
AWS_URL=http://localhost:9004/default

filesystems.php →

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

References:

Laravel Minio

like image 102
Tatachiblob Avatar answered Jan 28 '26 14:01

Tatachiblob



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!