try{ // Persist the model into the model manager this uploads and resizes the image
$this->getManager()->persist($media); }catch(ORMException $e){ thrownewCustomValidationException(sprintf('Some error occurred while persisting your media')); }finally{ // Cleanup temporary file
$this->deleteTmpFile($file); }