0

How can I upload a file using JMS Serializer? Now I'm getting Notice: Array to string conversion

App\Entity\Answer

/**
 * @Type("string")
 * @ORM\Column(type="string", length=255, nullable=true)
 */
private $file;

App\Controller\AnswerController

$data = array_replace_recursive(
    $request->request->all(),
    $request->files->all()
);

$serializer = SerializerBuilder::create()->build();
$object = $serializer->deserialize(json_encode($data), Answer::class, 'json');

$em = $this->getDoctrine()->getManager();
$em->persist($object);
$em->flush();
  • I think your problem is you get a file from request and you serialize/deserialize it to an array ... not a string. You need to be explicit about the way you want your file to be serialized/deserialized. Maybe with an @accessor annotation – Yoann MIR Jul 10 '19 at 07:05
  • Also you should take a look at VichUploaderBUndle to handle your uploads along with JMS – Yoann MIR Jul 10 '19 at 07:05

0 Answers0