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; } 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([