我有一个symfony网站,并且正在对其api进行休息,并且我将要上传一个实体的图像,并进行邮递员测试,但是当我意识到它时,JSON响应使我退缩了为空。请注意,我使用vichuploaderbundle上传图片。
控制器
/**
* @Route("/api/admin/assurance/logo/{id}")
* @Rest\View()
* @Method("PUT")
*/
public function putLogoEditAction(
Request $request,
Assurance $assurance,
$formType = null,
$logoId = null
){
$em = $this->getDoctrine()->getManager();
$logofile = $request->files->get('file');
$logofile = $this->getLogoFile($logoId);
$assurance->setLogo($logofile);
$form = $this->createForm('Doctix\MedecinBundle\Form\LogoType', $logofile);
$form->submit($request->request->all());
if ($form->isValid()){
$em = $this->getDoctrine()->getManager();
$em->persist($logofile);
$em->flush();
return $logofile;
}
return $form;
}
private function getLogoFile($logoId)
{
if (null === $logoId) {
return new Logo();
}
$logofile = $this->getDoctrine()->getRepository('DoctixMedecinBundle:Logo')->find($logoId);
return $logofile;
}
实体
/*
* @Vich\UploadableField(mapping="media_image", fileNameProperty="logoName")
*
* @var File
*/
private $logoFile;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*
* @var string
*/
private $logoName;
表格
->add('logoFile', VichImageType::class, [
'required' => false,
'allow_delete' => true,
'download_label' => true,
'download_uri' => true,
'image_uri' => true,
'imagine_pattern' => 'null',
]);
用邮递员测试
我尝试通过保险ID向保险中添加徽标,为此,我添加了下一个json,但它返回的空代码为200。这是邮递员的屏幕截图:
与邮递员取得联系
在此屏幕快照中,您将找到GET请求的结果,该请求概述了具有名称和徽标以及医生可以加入的保险实体的内容
谢谢