I have a rare case where I need a route for a specific asset. I need to return an asset like I would in Twig, but directly in a Controller action. I use the AssetMapper component for versioned assets as well.
I tried using an asset Package
like the Asset Component documentation suggests, but get a FileNotFoundException (The file "images/logo/logo-full.webp" does not exist)
exception.
My code is as follows:
public function logo(): BinaryFileResponse {
$asset = new Asset(new EmptyVersionStrategy());
return $this->file($asset->getUrl('images/logo/logo-full.webp'));
}