FileUpload with Laravel Sail && Minio

I understand there was some sort of difficulties with livewire and minio when it comes to temporary signed urls. I've configured livewire to use the "local" disk for temporary file uploads, however when I try to submit the form, nothing happens. The file upload field resets and is blank. Earlier, I tried setting the temp file upload to "s3" and the livewire-tmp folder with the image was actually uploaded to my minio instance, however when I tried to submit the form, it acted as it the file wasn't the right type and triggered a validation error that it shouldn't have. Any idea how I can get file uploads to work with minio?
11 Replies
Dan Harrin
Dan Harrin2y ago
please send the code you tried for the file upload i have used minio without issues before
bahamasoul
bahamasoulOP2y ago
@danharrin
<?php

namespace App\Http\Livewire\Components\Administration;

use App\AdminSetting;
use Livewire\Component;
use Illuminate\Contracts\View\View;
use App\View\Components\AdminLayout;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Concerns\InteractsWithForms;

class EditAdminSettings extends Component implements HasForms
{
use InteractsWithForms;

public ?array $data = [];

public AdminSetting $record;

public function mount(): void
{
$this->record = AdminSetting::all()->first();

$this->form->fill($this->record->attributesToArray());
}

protected function getFormSchema(): array
{
return [
FileUpload::make('chairman_signature')
->image()
->enableOpen()
->enableDownload()
->preserveFilenames()
->disk('s3')
->directory('admin_settings/chairman_signature'),
];
}

public function edit(): void
{
$data = $this->form->getState();

$this->record->update($data);
}

protected function getFormModel(): AdminSetting
{
return $this->record;
}

protected function getFormStatePath(): string
{
return 'data';
}

public function render(): View
{
return view('livewire.components.administration.edit-admin-settings')
->layout(AdminLayout::class, [
'title' => 'Administrative settings',
]);
}
}
<?php

namespace App\Http\Livewire\Components\Administration;

use App\AdminSetting;
use Livewire\Component;
use Illuminate\Contracts\View\View;
use App\View\Components\AdminLayout;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Concerns\InteractsWithForms;

class EditAdminSettings extends Component implements HasForms
{
use InteractsWithForms;

public ?array $data = [];

public AdminSetting $record;

public function mount(): void
{
$this->record = AdminSetting::all()->first();

$this->form->fill($this->record->attributesToArray());
}

protected function getFormSchema(): array
{
return [
FileUpload::make('chairman_signature')
->image()
->enableOpen()
->enableDownload()
->preserveFilenames()
->disk('s3')
->directory('admin_settings/chairman_signature'),
];
}

public function edit(): void
{
$data = $this->form->getState();

$this->record->update($data);
}

protected function getFormModel(): AdminSetting
{
return $this->record;
}

protected function getFormStatePath(): string
{
return 'data';
}

public function render(): View
{
return view('livewire.components.administration.edit-admin-settings')
->layout(AdminLayout::class, [
'title' => 'Administrative settings',
]);
}
}
LeandroFerreira
sounds like a validation... could you try without ->image() please? did you try a .jpg?
bahamasoul
bahamasoulOP2y ago
Hey, yeah I did. Same issue. No validation seems to work. It's almost as if it can't retrieve the file from the temp server on minio even though it is uploaded there successfully in the livewire-tmp folder, however I would assume if it couldn't find the file it would trigger the "required" validation rule instead; so not sure.
LeandroFerreira
is the bucket public? did you config the .env? something like this?
FILESYSTEM_DRIVER=s3
AWS_ACCESS_KEY_ID=sail
AWS_SECRET_ACCESS_KEY=password
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=local
AWS_ENDPOINT=http://minio:9000
AWS_URL=http://localhost:9000/local
AWS_USE_PATH_STYLE_ENDPOINT=true
FILESYSTEM_DRIVER=s3
AWS_ACCESS_KEY_ID=sail
AWS_SECRET_ACCESS_KEY=password
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=local
AWS_ENDPOINT=http://minio:9000
AWS_URL=http://localhost:9000/local
AWS_USE_PATH_STYLE_ENDPOINT=true
bahamasoul
bahamasoulOP2y ago
Yes the bucket is public.
AWS_ACCESS_KEY_ID=sail
AWS_SECRET_ACCESS_KEY=password
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=hpc-local
AWS_ENDPOINT=http://localhost:9000
AWS_URL=http://localhost:9000/hpc-local
AWS_USE_PATH_STYLE_ENDPOINT=true
AWS_ACCESS_KEY_ID=sail
AWS_SECRET_ACCESS_KEY=password
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=hpc-local
AWS_ENDPOINT=http://localhost:9000
AWS_URL=http://localhost:9000/hpc-local
AWS_USE_PATH_STYLE_ENDPOINT=true
LeandroFerreira
should work... can you share the project on github? Send me a DM please... try AWS_ENDPOINT=http://minio:9000
bahamasoul
bahamasoulOP2y ago
@Leandro Ferreira Wow. That actually worked. Insane. Any idea why that worked? @Leandro Ferreira
LeandroFerreira
nice! not sure, but inside the docker we should use minio:9000
bahamasoul
bahamasoulOP2y ago
Thanks a lot! Cookies and ice cream for you.
KudoNghia
KudoNghia13mo ago
I have issue when i submit form , it not working save attachments on database , plz help me ? Code exam : FileUpload::make('attachments') ->disk('s3') ->directory('form-attachments') ->preserveFilenames() ->openable() ->reorderable() ->appendFiles(),
Want results from more Discord servers?
Add your server