/**
  * Handle the upload request.
  *
  * @param Request                               $request
  * @param \Symfony\Component\Form\FormInterface $form
  * @param array                                 $config
  *
  * @throws \SRIO\RestUploadBundle\Exception\UploadException
  * @return UploadResult
  */
 public function handleRequest(Request $request, FormInterface $form = null, array $config = array())
 {
     try {
         $processor = $this->getProcessor($request, $config);
         return $processor->handleUpload($request, $form, $config);
     } catch (UploadException $e) {
         if ($form != null) {
             $form->addError(new FormError($e->getMessage()));
         }
         $result = new UploadResult();
         $result->setException($e);
         $result->setForm($form);
         return $result;
     }
 }