F
Filament5mo ago
Felix

how to upload file to an s3 bucket in the beforeCreate function?

Hello, I want upload an png to an s3 bucket via the beforeCreate function, this is the first time I am using s3 so I am some what green with this. I am working this way becase I am using it to upload info to an api and then halting it. but i don't know how to get the (temporary) file in the beforeCreate to upload them. I have installed league/flysystem-aws-s3-v3, and put in my AWS S3 in the .env file. and have tested the the functions in the Laravel and Livewire docs, but it doesn't work. how do you save files to an S3 in an beforeCreate? And this is my code if you are interested: protected function beforeCreate(): void { // this doesn't work [ foreach ($this->oldFormState['data']['header_image'] as $img){ dd($img); $img->store('photos', 's3'); } $result = $this->data['header_image']->store('photos', 's3-public'); dd($this); // ] $this->data['event']['languages'] = json_encode($this->data['event']['select_languages']); $event = Live::events()->post($this->data)->body(); $event_data =json_decode($event); if ($event_data->type == 'error'){ Notification::make() ->title('De link "' .$event_data->value. '" word al gebruikt!') ->warning() ->send(); $this->halt(); } Notification::make() ->title('Opslaan succesvol') ->success() ->send(); redirect()->route('filament.admin.event.resources.events.edit', ['record' => json_decode($event_data->value->id)]); $this->halt(); }
2 Replies
LeandroFerreira
LeandroFerreira5mo ago
maybe saving the file afterStateUpdated?
FileUpload::make('header_image')
->live()
->afterStateUpdated(function (FileUpload $component) {
$component->saveUploadedFiles();
})
FileUpload::make('header_image')
->live()
->afterStateUpdated(function (FileUpload $component) {
$component->saveUploadedFiles();
})
Felix
FelixOP5mo ago
I have yet to test it fully, but with this method the file doesn't preview. before the presing the save button. I have checked with my colleague and sadly it didn't save.
Want results from more Discord servers?
Add your server