Skip to content

problems with YAML mapping #1515

Open
Open
@fwtag-tnm

Description

@fwtag-tnm
Q A
Bundle version 2.7.0
Symfony version 7.2.8
PHP version 8.2.29

Support Question

Hi there, I am trying to use a YAML mapper for mapping of my Entity, but keep getting this error:

        "@context": "/api/contexts/Error",
	"@id": "/api/errors/500",
	"@type": "Error",
	"title": "An error occurred",
	"detail": "Mapping not found for field \"file\"",
	"status": 500,
	"type": "/errors/500",

It seems as if the mapping is not loaded at all. auto_detectionis not swicthed off.

My config:

# config/packages/vich_uploader.yaml
vich_uploader:
  db_driver: orm
  storage: flysystem

  metadata:
    type: attribute

  mappings:
    local:
      uri_prefix: ''
      upload_destination: default.storage
      namer:
        service: Vich\UploaderBundle\Naming\HashNamer
        options: { algorithm: 'sha256', length: 32 }
      directory_namer:
        service: Vich\UploaderBundle\Naming\SubdirDirectoryNamer
        options: { chars_per_dir: 1, dirs: 5 }
# config/vich_uploader/Entity.Resource.yaml
App\Entity\Resource:
  file:
    mapping: 'local'
    file_name_property: 'filePath'
    size: 'fileSize'
    mime_type: 'mimeType'
    original_name: 'originalFileName'

The relevant parts of App\Entity\Resource:

namespace App\Entity;

...

#[ApiResource(
...
)]
...
#[Vich\Uploadable]
final class Resource
{
...
    public function __construct(
    ...
        #[Groups(['resource:write'])]
        public ?File $file = null,
    ...
    ) 
    {
    }
    ....
}

I followed the documentation here https://github.com/dustin10/VichUploaderBundle/blob/master/docs/mapping/yaml.md and also altered the YAML file name, the Entity FQN, etc., but keep getting this error.

What am I doing wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions