public function actionUploadImage(): Response
    {
        $model = Yii::createObject($this->attachmentModelClass);
        $model->file = UploadedFile::getInstanceByName('file');

        if (!$model->save()) {
            throw new UnprocessableEntityHttpException($model->getFirstError('file'));
        }

        return $this->asJson([
            'link' => $model->getFileUrl('origin'),
        ]);
    }
public function actionUploadImage(): Response
    {
        $model = Yii::createObject($this->attachmentModelClass);
        $model->file = UploadedFile::getInstanceByName('file');

        if (!$model->save()) {
            throw new UnprocessableEntityHttpException($model->getFirstError('file'));
        }

        return $this->asJson([
            'link' => $model->getFileUrl('origin'),
        ]);
    }
public function actionUploadImage ( ) : Response { $ model = Yii :: createObject ( $ this -> attachmentModelClass ) ; $ model -> file = UploadedFile :: getInstanceByName ( 'file' ) ; if ( ! $ model -> save ( ) ) { throw new UnprocessableEntityHttpException ( $ model -> getFirstError ( 'file' ) ) ; } return $ this -> asJson ( [ 'link' => $ model -> getFileUrl ( 'origin' ) , ] ) ; }
Upload an image

@return Response

@throws UnprocessableEntityHttpException
Upload an image