DataUriInterface, enabling seamless integration with existing serialization workflows.1tomany/data-uri library handles the heavy lifting of file-to-Data URI conversion, allowing the bundle to focus on Symfony-specific integrations (e.g., denormalizers, console commands).DataUriInterface, reducing friction for adoption.onetomany:data-uri:encode-file command provides a manual override for testing or one-off conversions, useful for debugging or non-serialized use cases.client_max_body_size).{"image": "data:image/png;base64,...}").composer require 1tomany/data-uri-bundle.DataUriInterface for a single entity (e.g., a ProductImage or Document model).php bin/console onetomany:data-uri:encode-file /path/to/file.@Groups({"api"})), ensure the denormalizer is configured for the relevant groups in config/packages/serializer.yaml.framework:
serializer:
mapping:
paths: ['%kernel.project_dir%/config/serializer']
symfony/serializer or 1tomany/data-uri in composer.json.config/bundles.php:
return [
// ...
OneToMany\DataUriBundle\OneToManyDataUriBundle::class => ['all' => true],
];
DataUriInterface implementation for a test entity (e.g., src/Entity/Image.php):
use OneToMany\DataUri\Contract\Record\DataUriInterface;
class Image implements DataUriInterface {
private string $path;
// ...
}
config/packages/serializer.yaml):
OneToMany\DataUriBundle\Serializer\DataUriNormalizer:
tags: [serializer.normalizer]
use Symfony\Component\Serializer\Annotation\Context;
class ProductController {
#[Context(['groups' => ['api']])]
public function getProduct(Product $product): JsonResponse {
return new JsonResponse($product);
}
}
use Symfony\Component\Validator\Constraints as Assert;
class Image {
#[Assert\File(maxSize: '1M')]
private string $path;
}
public function getDataUri(): string {
try {
return $this->encodeFile($this->path);
} catch (Exception $e) {
return $this->generateFallbackUrl();
}
}
How can I help you explore Laravel packages today?