R
R
ragnar_ok2019-07-09 23:42:38
symfony
ragnar_ok, 2019-07-09 23:42:38

How to upload a file using JMS Serializer?

I'm developing a REST API using Symfony 4. How to upload a file using JMS Serializer? Now outputs: 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();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shaqster, 2019-07-11
@shaqster

The easiest option is to turn the file into base64 on the client

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question