isPost()) { throw new BadRequest(); } list($prefix, $contents) = explode(',', $data); $contents = base64_decode($contents); $attachment = $this->getEntityManager()->getEntity('Attachment'); $this->getEntityManager()->saveEntity($attachment); $this->getContainer()->get('fileManager')->putContents('data/upload/' . $attachment->id, $contents); return array( 'attachmentId' => $attachment->id ); } }