public function afterUpload($data) { if (isset($data['params']) === false) { return ['error' => 'bad request']; } if (isset($data['params']['objectId'], $data['filename'], $data['params']['modelId']) === false) { return ['error' => 'bad request']; } if ($data['params']['modelId'] === 'null') { $data['params']['modelId'] = 0; } $image = new Image(['object_id' => $data['params']['objectId'], 'object_model_id' => $data['params']['modelId'], 'filename' => $data['filename'], 'image_title' => '', 'sort_order' => 0]); if ($image->save()) { return ArrayHelper::merge($image->toArray(), ['file' => $image->file]); } else { return $image->getErrors(); } }