# Save hasMany Images causes Object of class Laminas\\Diactoros\\UploadedFile could not be converted to string Error

**URL:** <https://discourse.cakephp.org/t/save-hasmany-images-causes-object-of-class-laminas-diactoros-uploadedfile-could-not-be-converted-to-string-error/10583>\
**Category:** Need Help\
**Created:** [August 22, 2022, 11:55pm UTC](https://discourse.cakephp.org/t/save-hasmany-images-causes-object-of-class-laminas-diactoros-uploadedfile-could-not-be-converted-to-string-error/10583 "2022-08-22T23:55:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Herzberg](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@Herzberg](https://discourse.cakephp.org/u/Herzberg)\
**Post date:** [August 22, 2022, 11:55pm UTC](https://discourse.cakephp.org/t/save-hasmany-images-causes-object-of-class-laminas-diactoros-uploadedfile-could-not-be-converted-to-string-error/10583/1 "2022-08-22T23:55:14Z")

</div>

Hi, if I am trying to upload many pictures at the same time i am getting an error that says: ‘Object of class Laminas\Diactoros\UploadedFile could not be converted to string’

StartsController.php:

```
    if ($this->request->is('post')) {
        $start->steps[] = $start;
        $start->setDirty('steps', true);
        
        $image2 = $this->request->getData();
        debug($image2);
        
        $recipe = $this->Start->patchEntity($start, $this->request->getData(), ['associated' => 
       ['Steps']]);

```

add.php (view):

echo $this-\>Form-\>control(‘steps.0.image’,[‘type’=\>‘file’]);

StepsTable.php:

```
        $validator
        ->allowEmptyFile('image')
        ->add( 'image', [
            'mimeType' => [
                'rule' => ['mimeType', [ 'image/jpg', 'image/png', 'image/jpeg'] ],
                'message' => 'Please upload only jpg and png.',
            ],
            'fileSize' => [
                'rule' => ['fileSize', '<=', '1MB'],
                'message' => 'Image file size must be less than 1MB.',
            ],
        ] );

```

* * *

The debug($image2) throws:

APP/Controller/StartsController.php (line 642)  
[  
‘title’ =\> ‘test’,  
‘steps’ =\> [  
(int) 0 =\> [  
‘body’ =\> ‘test’,  
‘image’ =\> object(Laminas\Diactoros\UploadedFile) id:0 {  
private clientFilename =\> ‘test.jpg’  
private clientMediaType =\> ‘image/jpeg’  
private error =\> (int) 0  
private file =\> ‘/tmp/phpsxf4LO’  
private moved =\> false  
private size =\> (int) 61717  
private stream =\> null  
},  
],

but the $recipe = $this-\>Start-\>patchEntity($start, $this-\>request-\>getData(), [‘associated’ =\> [‘Steps’]]); throws the error:

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

Any ideas? Thanks..

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [August 23, 2022, 1:14am UTC](https://discourse.cakephp.org/t/save-hasmany-images-causes-object-of-class-laminas-diactoros-uploadedfile-could-not-be-converted-to-string-error/10583/2 "2022-08-23T01:14:43Z")

</div>

Does [this](https://stackoverflow.com/questions/60755872/cakephp-object-of-class-laminas-diactoros-uploadedfile-could-not-be-converted) help?

---

<div class="post-metadata">

**Author:** ![Herzberg](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@Herzberg](https://discourse.cakephp.org/u/Herzberg)\
**Post date:** [August 23, 2022, 10:48am UTC](https://discourse.cakephp.org/t/save-hasmany-images-causes-object-of-class-laminas-diactoros-uploadedfile-could-not-be-converted-to-string-error/10583/3 "2022-08-23T10:48:59Z")

</div>

thanks i found that post before but i didnt look any closer because:

‘width’ =\> [Validation::COMPARE\_GREATER\_OR\_EQUAL, 10],  
‘height’ =\> [Validation::COMPARE\_GREATER\_OR\_EQUAL, 10],

was deprecated … BUT now i see that what he wrotes before was right. The column in the database should not have the same name as what you provide with the form control… I did this before without problems (without hasmany) but in this case it should def. have a different name!

thanks
