Vichuploader & API 平台文件未保存

Vichuploader & API platform File is not saved

我的问题实际上是用vich上传文件。它与其他实体完美配合。但在我用户的实体中它不起作用。

Vich 上传器配置:

vich_uploader:
db_driver: orm
mappings:
   user_cover:
       uri_prefix: /media/users
       upload_destination: '%kernel.project_dir%/public/media/users'
       namer: Vich\UploaderBundle\Naming\OrignameNamer
       delete_on_update:   true
       delete_on_remove:   true
   play_media:
       uri_prefix: /media/defis
       upload_destination: '%kernel.project_dir%/public/media/defis'
       namer: Vich\UploaderBundle\Naming\OrignameNamer
       delete_on_update:   true
       delete_on_remove:   true    

play_media 映射完美无缺,但我的问题来自 user_cover

我的用户实体中相关的部分:

   /**
               * @ORM\Column(type="string", length=255, nullable=true)
               */
               #[Groups(['read:User'] )]
               private $CoverPath;
           
                /**
                * @var File|null
                * @Assert\File(
                *     maxSize = "2048k",
                *     mimeTypes = {"image/jpeg", "image/png"},
                *     mimeTypesMessage = "Please upload a valid cover image: jpeg or png under 2048k")
                * @Vich\UploadableField(mapping="play_media_test", fileNameProperty="CoverPath")
                */
                private $file;    


 /**
                * Set the value of file
                *
                *  @param File|null  $file
                *  @return User
                */ 
               public function setFile(?File $file = null) :User
               {
           
                   $this->file = $file;
           
                   if ($file instanceof File) {
                       $this->setUpdatedAt(new \DateTime());
                   }
           
                   return $this;
                   
               }    

和我的控制器(还没有检查),理论上我认为我不应该更新日期,因为 setter 已经在做并且不需要使用实体管理器(我试过了), 但是...:[=​​15=]

public function __invoke(Request $request)
{
    $user_data = $request->attributes->get('data');
    $user_data->setFile($request->files->get('cover'));
    $user_data->setUpdatedAt(new DateTime());
    return $user_data;
}    

和操作配置:

'cover' => [
                   'method' => 'POST' ,
                   'path' => 'user/{id}/cover',
                   'deserialize' => false,
                   'controller' => PostCoverUserController::class,
                   'openapi_context' => [
                       'security' => 
                       [['bearerAuth' => []]], 
                       'summary'     => 'Update the user cover image ',
                       'requestBody' => [
                           'content' => [
                               'multipart/form-data' => [
                                   'schema' => [
                                       'type' => 'object',
                                       'properties' => [
                                           'cover' => [
                                               'type' => 'string', 
                                               'format' => 'biniray'
                                           ]
                                       ]
                                   ]
                               ]
                           ]
                       ]
                       ]                                                                      
               ],    

我多次重读我的代码,但我不明白为什么持久化没有按预期工作?但是我的其他上传效果很好。 api 发回答案,dd 有效 .. 只有持久性失败。 谢谢你的帮助

问题来自服务器的缓存: php 垃圾箱/控制台 cache:clear ;)