F
Filament15mo ago
giagara

File upload on s3 with Minio (sail)

Hi, I've alredy read the other posts about this topic but i can't get it working. The scenario: A category resource where i want to upload a picture that should be public (think about a sort of eccomerce). In the resource (form) i have
Forms\Components\FileUpload::make('picture')
->disk('s3')
->directory('categories')
Forms\Components\FileUpload::make('picture')
->disk('s3')
->directory('categories')
in .env:
AWS_ACCESS_KEY_ID=something
AWS_SECRET_ACCESS_KEY=something
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=mybucketname
AWS_USE_PATH_STYLE_ENDPOINT=true
AWS_ENDPOINT=http://minio:9000
AWS_URL=http://localhost:9000/local
AWS_ACCESS_KEY_ID=something
AWS_SECRET_ACCESS_KEY=something
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=mybucketname
AWS_USE_PATH_STYLE_ENDPOINT=true
AWS_ENDPOINT=http://minio:9000
AWS_URL=http://localhost:9000/local
Using something like Storage::disk('s3')->put('categories/asd.txt','asd');works like a charm, but when i do it from web interface it gives me an error. What seems strange is that filament tries to upload directly the picture to minio: livewire.js?id=11c49d7e:3953 PUT http://minio:9000/mybucketname/livewire-tmp/jiuIgVyZYQO9hFAyFvZT9bvf5q3zrx-metaYjMuanBn-.jpg?x-amz-acl=private&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=4VfWaDjtRdnIjFh1osj9%2F20230830%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20230830T081610Z&X-Amz-SignedHeaders=host%3Bx-amz-acl&X-Amz-Expires=300&X-Amz-Signature=0bac68f62bcceb8eeeab1ca27fe157095c927aa2df4924f8bb8f3e104f7f5c3a net::ERR_NAME_NOT_RESOLVED am i missing something? thanks
4 Replies
mtbossa
mtbossa15mo ago
I think this error happens because the host machine does not know how to resolve "http://minio:9000". However, Laravel container knows, that's why it works inside the application, but not in the browser when Filepond makes the request. I'm trying to find a solution for that So, I managed to find a solution. I don't know if this is the best one, but it's working for now. In my docker-compose file I added the following:
minio:
image: 'minio/minio:latest'
ports:
- '${FORWARD_MINIO_PORT:-9000}:9000'
- '${FORWARD_MINIO_CONSOLE_PORT:-8900}:8900'
environment:
MINIO_ROOT_USER: 'sail'
MINIO_ROOT_PASSWORD: 'password'
volumes:
- 'sail-minio:/data/minio'
networks:
sail:
ipv4_address: 172.20.0.5
command: minio server /data/minio --console-address ":8900"
healthcheck:
test: [ "CMD", "curl", "-f", "http://localhost:9000/minio/health/live" ]
retries: 3
timeout: 5s
networks:
sail:
ipam:
config:
- subnet: 172.20.0.0/24
minio:
image: 'minio/minio:latest'
ports:
- '${FORWARD_MINIO_PORT:-9000}:9000'
- '${FORWARD_MINIO_CONSOLE_PORT:-8900}:8900'
environment:
MINIO_ROOT_USER: 'sail'
MINIO_ROOT_PASSWORD: 'password'
volumes:
- 'sail-minio:/data/minio'
networks:
sail:
ipv4_address: 172.20.0.5
command: minio server /data/minio --console-address ":8900"
healthcheck:
test: [ "CMD", "curl", "-f", "http://localhost:9000/minio/health/live" ]
retries: 3
timeout: 5s
networks:
sail:
ipam:
config:
- subnet: 172.20.0.0/24
MinIO always get the same IP address now. We can add now change AWS_ENDPOINT=http://minio:9000 to AWS_ENDPOINT=http://172.20.0.5:9000, and everything is going to work. The file will be uploaded in the browser, and the path will be properly saved in the database.
Luiz
Luiz10mo ago
I tried your solution, but it did not resolve.
eduardichim
eduardichim6mo ago
@giagara not sure if you've figured out how to do it... but is so damn simple took me 30 minutes after trying the docker-compose solution proposed by @mtbossa I just added 127.0.0.1 minio to my hosts file No other changes are required, because the browser will try to access minio:9000 same as the laravel container so you just have to tell it that minio on the host is localhost Docker network will solve the rest for minio:9000 with it's internal network IPs and all that stuff
mtbossa
mtbossa6mo ago
Yes, this is definitely a solution. I don't like this approach of having to mess with hosts file... But I think that there aren't many solution for this, at least for now
Want results from more Discord servers?
Add your server