# Object of class Laminas\\Diactoros\\UploadedFile could not be converted to string

**URL:** <https://discourse.cakephp.org/t/object-of-class-laminas-diactoros-uploadedfile-could-not-be-converted-to-string/9312>\
**Category:** Need Help\
**Created:** [May 2, 2021, 1:25am UTC](https://discourse.cakephp.org/t/object-of-class-laminas-diactoros-uploadedfile-could-not-be-converted-to-string/9312 "2021-05-02T01:25:51Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![dirk](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dirk/32/2174_2.png) [@dirk](https://discourse.cakephp.org/u/dirk)\
**Post date:** [May 3, 2021, 1:31pm UTC](https://discourse.cakephp.org/t/object-of-class-laminas-diactoros-uploadedfile-could-not-be-converted-to-string/9312/21 "2021-05-03T13:31:04Z")

</div>

> [@makamo66](#):
>
> When I didn’t upload an image, I got the error: Call to a member function getError() on array

Could you post the error message, or a screenshot?

When you hit the submit button and nothing seems to happen, could you please open the “variables” in your lower debug menu and check, if there are validation errors?

---

<div class="post-metadata">

**Author:** ![dirk](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dirk/32/2174_2.png) [@dirk](https://discourse.cakephp.org/u/dirk)\
**Post date:** [May 3, 2021, 1:33pm UTC](https://discourse.cakephp.org/t/object-of-class-laminas-diactoros-uploadedfile-could-not-be-converted-to-string/9312/22 "2021-05-03T13:33:59Z")

</div>

> [@makamo66](#):
>
> `$image1 = $this->request->getData('image1');`  
> to  
> `$image1 = $this->request->getUploadedFile('image1');`

could you undo these change?, because I don#t know the behavior of “getUploadedFile” and I work with “getData”

---

<div class="post-metadata">

**Author:** ![makamo66](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/makamo66/32/2156_2.png) [@makamo66](https://discourse.cakephp.org/u/makamo66)\
**Post date:** [May 3, 2021, 2:12pm UTC](https://discourse.cakephp.org/t/object-of-class-laminas-diactoros-uploadedfile-could-not-be-converted-to-string/9312/23 "2021-05-03T14:12:57Z")

</div>

If I change  
`$image1 = $this->request->getUploadedFile('image1');`  
back to  
`$image1 = $this->request->getData('image1');`  
I get the error message that you can see in the screenshot. If I use `getUploadedFile('image1')` instead, I get the following errors in my variables:  
‘recipe’ =\> [  
‘image1’ =\> [  
‘scalar’ =\> ‘The provided value is invalid’,  
‘maxLength’ =\> ‘The provided value is invalid’,  
],  
],

So I changed the Recipes Table to

```auto
       $validator
            //->scalar('image1')
            //->maxLength('image1', 200)
            //->allowEmptyFile('image1');
	    ->isArray('image1')
	    ->allowEmptyArray('image1');

```

and now everything works!

---

<div class="post-metadata">

**Author:** ![makamo66](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/makamo66/32/2156_2.png) [@makamo66](https://discourse.cakephp.org/u/makamo66)\
**Post date:** [May 3, 2021, 2:13pm UTC](https://discourse.cakephp.org/t/object-of-class-laminas-diactoros-uploadedfile-could-not-be-converted-to-string/9312/24 "2021-05-03T14:13:47Z")

</div>

![error_050321](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/6/61b9b6c5a59e6baced60c4c6dae57e8181390e42.gif)

[Previous page](https://discourse.cakephp.org/t/object-of-class-laminas-diactoros-uploadedfile-could-not-be-converted-to-string/9312.md?page=1)
