From e63456bd97e70ad77705a6ed2e2b8428e6eabf65 Mon Sep 17 00:00:00 2001 From: dev Date: Sun, 15 Mar 2026 13:57:00 +0300 Subject: [PATCH 1/2] [fix] Remove relativePath from File model MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit relativePath was intended for S3 image-bundle integration but caused issues with filesystem storage — the path excluded the storage prefix (e.g. uploads/) making image loader unable to find files. The correct approach for S3 is to use S3Loader in image-bundle, not a special path in the File model. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/Handler/Handler.php | 4 ++-- src/Model/File.php | 6 ------ src/Model/FileInterface.php | 2 -- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/Handler/Handler.php b/src/Handler/Handler.php index d6f0cb7..ba93f23 100644 --- a/src/Handler/Handler.php +++ b/src/Handler/Handler.php @@ -96,7 +96,7 @@ public function upload(ExtensionMetadataInterface $metadata, object $object, str $resolvedPath = $storage->resolvePath($relativePath); $uri = $storage->resolveUri($relativePath); - $file = new File($resolvedPath, $uri, $relativePath); + $file = new File($resolvedPath, $uri); $metadata->setFieldValue($object, $inversedBy, $file); $this->dispatcher->dispatch(new PostUploadEvent($object, $file, $fieldName)); @@ -163,7 +163,7 @@ public function inject(ExtensionMetadataInterface $metadata, object $object, str $path = $storage->resolvePath($relativePath); $uri = $storage->resolveUri($relativePath); - $file = new File($path, $uri, $relativePath); + $file = new File($path, $uri); $metadata->setFieldValue($object, $fieldName, $file); } diff --git a/src/Model/File.php b/src/Model/File.php index 9806c24..464ceff 100644 --- a/src/Model/File.php +++ b/src/Model/File.php @@ -18,7 +18,6 @@ class File extends \Symfony\Component\HttpFoundation\File\File implements FileIn public function __construct( string $path, public readonly ?string $uri = null, - private readonly ?string $relativePath = null, ) { parent::__construct($path, false); } @@ -28,11 +27,6 @@ public function getUri(): ?string return $this->uri; } - public function getRelativePath(): ?string - { - return $this->relativePath; - } - #[\Override] public function isFile(): bool { diff --git a/src/Model/FileInterface.php b/src/Model/FileInterface.php index da193d5..4930100 100644 --- a/src/Model/FileInterface.php +++ b/src/Model/FileInterface.php @@ -14,6 +14,4 @@ interface FileInterface { public function getUri(): ?string; - - public function getRelativePath(): ?string; } From b31b2cf6a70717a3eae8d33e8a4315c7f1e11517 Mon Sep 17 00:00:00 2001 From: dev Date: Sun, 15 Mar 2026 14:11:55 +0300 Subject: [PATCH 2/2] [fix] S3Storage::download() strips URI prefix for image-bundle compatibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When image-bundle's S3Loader passes a full URI (e.g. https://cdn/abc.jpg) to download(), strip the configured uriPrefix to extract the S3 key. This allows Twig macros to use src.uri|default(src) universally — both filesystem and S3 paths resolve correctly without special handling. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/Storage/S3Storage.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Storage/S3Storage.php b/src/Storage/S3Storage.php index 1b7dd07..45c0778 100644 --- a/src/Storage/S3Storage.php +++ b/src/Storage/S3Storage.php @@ -111,9 +111,22 @@ public function resolveRelativePath(string $path, string $prefix = ''): string return $prefix.'/'.\ltrim(\basename($path), '/'); } + /** + * Strip the configured URI prefix from a path (e.g. full S3 URL → S3 key). + * Used by image-bundle's S3Loader which receives the full URI from Twig. + */ + private function stripUriPrefix(string $path): string + { + if (null !== $this->uriPrefix && \str_starts_with($path, $this->uriPrefix)) { + return \substr($path, \strlen($this->uriPrefix)); + } + + return $path; + } + public function download(string $relativePath, string $targetPath): void { - $key = \ltrim($relativePath, '/'); + $key = \ltrim($this->stripUriPrefix($relativePath), '/'); try { $this->client->getObject([