diff --git a/CHANGELOG.md b/CHANGELOG.md index 27a26d0117..dfeb38ae69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file. This projec + [#129](https://github.com/luyadev/luya-module-admin/issues/129) Fixed problem when ngrest plugin try to write in object property instead of active record attribute. + [#125](https://github.com/luyadev/luya-module-admin/issues/125) Detach cruft behavior for global search response. ++ [#132](https://github.com/luyadev/luya-module-admin/pull/132) Fixed validation error on single file upload with the StorageUploadValidator. ## 1.2.0 (17. May 2018) diff --git a/src/ngrest/validators/StorageUploadValidator.php b/src/ngrest/validators/StorageUploadValidator.php index 20acd8d183..10aca8b87c 100644 --- a/src/ngrest/validators/StorageUploadValidator.php +++ b/src/ngrest/validators/StorageUploadValidator.php @@ -86,14 +86,18 @@ public function validateAttribute($model, $attribute) return; } - $files = $this->multiple ? UploadedFile::getInstances($model, $attribute) : (array) UploadedFile::getInstance($model, $attribute); - + $files = $this->multiple ? UploadedFile::getInstances($model, $attribute) : UploadedFile::getInstance($model, $attribute); + $contextModel = new DynamicModel(['file' => $files]); $contextModel->addRule(['file'], 'file', ['maxFiles' => $this->multiple ? 0 : 1])->validate(); - + if ($contextModel->hasErrors()) { return $this->addError($model, $attribute, $contextModel->getFirstError('file')); } + + if (!is_array($files)) { + $files = [$files]; + } $data = []; foreach ($files as $file) {