Example #1
0
 /**
  * @operationName("Upload Encoded Media")
  * @operationDescription("Upload Base64 encoded media (from Browser drag and drop)")
  */
 public function encodeAction()
 {
     if (!$this->request->isPost()) {
         $this->response->setStatusCode('400', 'No Upload Files');
         return $this->response->setJsonContent(array('errors' => array(array('code' => 400, 'message' => 'ERR_FILE_NO_UPLOAD'))));
     }
     $upload = new Models\Upload();
     $fileinfo = array();
     try {
         $file = $upload->uploadByEncodedData($this->request->getPost('file'), $this->request->getPost('name'), $this->request->getPost('type'));
         if ($file) {
             $fileinfo = $file->toArray();
             $fileinfo['localUrl'] = $file->getLocalUrl();
         }
     } catch (\Exception $e) {
         return $this->showExceptionAsJson($e, $upload->getMessages());
     }
     return $this->response->setJsonContent($fileinfo);
 }