multipart/form-data and FormType validation

105 views
Skip to first unread message

Malachi Soord

unread,
Aug 18, 2014, 4:55:04 AM8/18/14
to resting-wi...@googlegroups.com

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 :)

Reply all
Reply to author
Forward
0 new messages