dustin10 / VichUploaderBundle

A simple Symfony bundle to ease file uploads with ORM entities and ODM documents.
MIT License
1.85k stars 520 forks source link

uri_prefix don't handle absolute directory_namer #1378

Open mysterty opened 1 year ago

mysterty commented 1 year ago

Bug Report

Q A
BC Break no
Bundle version 2.1.1
Symfony version 6.1.12
PHP version 8.2.4

Summary

uri_prefix add an unwished "/" in the beginning of files' url if directory namer already begin with a "/".

Current behavior

Using directory_namer, uri_prefix add a "/" in beginning, resulting to something like //path/to/file.jpg and is wrong (like in vich uploader field in form). Need to set uri_prefix to 'uploads/..' to prevent it or change the directory namer to send a string not beginning by a "/"

How to reproduce

use directory_namer :

vich_uploader:
  db_driver: orm
  storage: flysystem

  mappings:
    media:
      uri_prefix: '' # 'uploads/..' is a working temp fix
      upload_destination: oneup_flysystem.default_filesystem_filesystem
      namer: Vich\UploaderBundle\Naming\SmartUniqueNamer
      directory_namer:
        service: vich_uploader.namer_directory_property
        options: { property: "directory", transliterate: false }
// Entity\Media.php
class Media
{
    private ?string $directory = '/uploads/medias/';
    [...]
    // ##################### Custom methods #####################

    public function getDirectory(): ?string
    {
        return $this->directory;
    }
}

Expected behavior

Default uri_prefix should handle if directory namer already begins by a "/".