I am building an API using the FOSRestBundle and am at the stage where I need to implement the handling of the creation of new entities that contain pictures.
Following the methods outlined on "Sending binary data along with a REST API request" sending the data as multipart/form-data feels the most practical for our implementation. Having the image keyed under 'data' and the entity under 'entity'
How can I configure a rest end point to both handle the file within the request and perform validation on the JSON encoded entity as well?
Previously when just sending the raw JSON I have been using symfony's form handleRequest method to perform validation against the custom FormType. For example:
$form = $this->createForm(new CommentType(), $comment, ['method' => 'POST']);$form->handleRequest($request);
if ($form->isValid()) {
// Is valid
}
I am relatively new to Symfony development so any tips/tricks would be grateful :)