/**
  * Provides upload file
  * @return mixed
  */
 public function actionUpload()
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $model = new Media();
     $routes = $this->module->routes;
     $rename = $this->module->rename;
     try {
         $model->saveUploadedFile($routes, $rename);
     } catch (\Exception $exc) {
         $response['files'][] = ['error' => $exc->getMessage()];
         return $response;
     }
     $bundle = MediaAsset::register($this->view);
     if ($model->isImage()) {
         $model->createThumbs($routes, $this->module->thumbs);
     }
     $response['files'][] = ['url' => $model->url, 'thumbnailUrl' => $model->getDefaultThumbUrl($bundle->baseUrl), 'name' => $model->filename, 'type' => $model->type, 'size' => $model->file->size, 'deleteUrl' => Url::to(['manage/delete', 'id' => $model->id]), 'deleteType' => 'POST'];
     return $response;
 }
 /**
  * Provides upload file
  * @return mixed
  */
 public function actionUpload()
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     if (Yii::$app->user->isGuest) {
         $response['files'][] = ['error' => 'Please, authorise to upload files.'];
         return $response;
     }
     $model = new Media();
     try {
         $model->saveUploadedFile($this->routes, $this->rename, $this->allowedFileTypes);
     } catch (\Exception $exc) {
         $response['files'][] = ['error' => $exc->getMessage()];
         return $response;
     }
     $bundle = MediaAsset::register($this->view);
     if ($model->isImage()) {
         $model->createThumbs($this->routes, $this->thumbs);
     }
     if ($this->defaultAlbumId) {
         $model->album_id = $this->defaultAlbumId;
         $model->save();
     }
     $response['files'][] = ['url' => $model->url, 'thumbnailUrl' => $model->getDefaultThumbUrl($bundle->baseUrl), 'id' => $model->primaryKey, 'name' => $model->filename, 'type' => $model->type, 'size' => $model->file->size, 'deleteUrl' => Url::to(['delete', 'id' => $model->id]), 'deleteType' => 'POST'];
     return $response;
 }