wyn
Preview images from S3
Found the answer, you have to pass the name (with the folder prefix if you have one)
to do that you can go to EditResource override mutateFormDataBeforeFill and add the prefix for each file, then it will be generated a s3 temporary link and you ll be able to preview it
3 replies
SpatieMediaLibraryUpload replace file in collection
and in createProduct which is app/Filament/Resources/Shop/ProductResource/Pages/CreateProduct.php
protected function handleRecordCreation(array $data): Model
{
$productModel = parent::handleRecordCreation($data);
if (isset($data['media'])) {
$mediaPath = $data['media'];
if (is_array($mediaPath)) {
foreach ($mediaPath as $path) {
$productModel->addMediaFromDisk($path, 's3')->toMediaCollection('products');
}
}
}
return $productModel;
}
}
8 replies
SpatieMediaLibraryUpload replace file in collection
i used
Forms\Components\Section::make('Images')
->schema([
FileUpload::make('media')
->preserveFilenames()
->disk('s3')
->imageEditorAspectRatios([
null,
'16:9',
'4:3',
'1:1',
])
->imageEditor()
->multiple()
->visibility('private')
->maxFiles(5)
])
->collapsible()
8 replies
Can't create a custom field
<?php
namespace App\Forms\Components;
use Filament\Forms\Components\Field;
use Illuminate\View\View;
class FileUploadColorForm extends Field
{
public $colors = [];
protected string $view = 'forms.components.file-upload-color';
public function getImages()
{
$images = [];
$files = \Storage::disk('livewire-tmp')->files();
foreach ($files as $file) { $images[] = [ 'file' => 'livewire-tmp/' . $file, ];
if (!isset($this->colors['livewire-tmp/' . $file])) { $this->colors['livewire-tmp/' . $file] = 'none'; logger($this->colors); } }
return $images; } public function render(): View { $this->getImages(); return view($this->view, ['colors' => $this->getImages()]); } public function mount() { \Log::info('Component state:', $this->colors); }
}
foreach ($files as $file) { $images[] = [ 'file' => 'livewire-tmp/' . $file, ];
if (!isset($this->colors['livewire-tmp/' . $file])) { $this->colors['livewire-tmp/' . $file] = 'none'; logger($this->colors); } }
return $images; } public function render(): View { $this->getImages(); return view($this->view, ['colors' => $this->getImages()]); } public function mount() { \Log::info('Component state:', $this->colors); }
}
2 replies