-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
Discussed in #3678
Originally posted by richardhulbert July 24, 2024
Hi
So I have a model called MediaStore and the following:
public static function MEDIA_TYPES(): array {
return ['image', 'video', 'audio', 'pdf'];
}
public function registerMediaCollections(): void {
foreach (self::MEDIA_TYPES() as $type)
if ($type === 'image') {
$this->addMediaCollection('image')->withResponsiveImages();
$this->addMediaConversion('thumb')->width(300)->crop('crop-center', 300, 200)->nonQueued();
}
$this->addMediaCollection($type);When I add media in the controller like this:
public function store(MediaStoreRequest $request) {
$new = MediaStore::create([
'name' => $request->name,
'description' => $request->description,
'type' => $request->type,
'user_id' => $request->user()->id
]);
try {
$new->addMediaFromRequest('file')->toMediaCollection(MediaStore::MEDIA_TYPES()[$request->type]);;
} catch (\Exception $exception) {
return response($exception->getMessage(), 502);
}
$media = $new->getMedia('*');
if (count($media) > 0) {
$new->url = $media[0]->getUrl();
if ((int) $new->type === 0) {
$new->thumb = $media[0]->getUrl('thumb');
$new->scrset = $media[0]->getSrcset();
}
}
return response($new->load('owner'));
}The thumb is generated straight away and the ResponsiveImages conversion is sent to the queue. I would expect both conversions to generate ConversionHasBeenCompleted events but this does NOT seems to be the case.
my listener:
class MediaConversionCompleteListener
{
public function __construct() {
}
public function handle(ConversionHasBeenCompleted $event): void {
$media = $event->media;
$path = $media->getPath();
$conversion = $event->conversion;
$conversionName = $conversion->getName();
Log::info("file {$path} has been converted using conversion:{$conversionName} for media {$media->id}");
}
}results in this in the log
[2024-07-24 14:52:43] local.INFO: file /Users/richard/PhpstormProjects/spa/storage/app/public/media/30/IMG_4840.HEIC has been saved for media 30
[2024-07-24 14:52:44] local.INFO: file /Users/richard/PhpstormProjects/spa/storage/app/public/media/30/IMG_4840.HEIC has been converted using conversion:thumb for media 30
I want to broadcast to the MediaStore that a new piece of media is ready to be used.
Ideas?
Metadata
Metadata
Assignees
Labels
No labels