# How to append an image to a product

**URL:** <https://forum.shopware.com/t/how-to-append-an-image-to-a-product/85819>\
**Category:** Programming (EN)\
**Created:** [9. März 2021 um 13:20 UTC](https://forum.shopware.com/t/how-to-append-an-image-to-a-product/85819 "2021-03-09T13:20:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![euroxid](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/euroxid/32/15105_2.png) [@euroxid](https://forum.shopware.com/u/euroxid)\
**Post date:** [9. März 2021 um 13:20 UTC](https://forum.shopware.com/t/how-to-append-an-image-to-a-product/85819/1 "2021-03-09T13:20:38Z")

</div>

I import products essentially by calling `productrepository.upsert(['name'=>...]);`  
What is the established best practice to append product pictures, so that they get saved to disk and all the media\_\* tables get populated?

Thanks!

---

<div class="post-metadata">

**Author:** ![euroxid](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/euroxid/32/15105_2.png) [@euroxid](https://forum.shopware.com/u/euroxid)\
**Post date:** [23. März 2021 um 20:36 UTC](https://forum.shopware.com/t/how-to-append-an-image-to-a-product/85819/3 "2021-03-23T20:36:52Z")

</div>

That is awesome, thank you so much.

My rather ugly approach was to first create the entity via the product repository with

```
 [
        'id' => <productid>,
        'productNumber' =>...,
        'media' => [
            [
                'id' => ...,
                'position' => 0,
                'media' => [
                        'id' => ...,
                        'fileName' => ...,
                        'fileSize' => ...,
                        'mediaFolderId' => $this->getDefaultProductMediaFolderId(),
                ]
            ]
        ]
    ]

```

then load that entity, work out the directory the picture is expected to be in, and save the image there.  
It kinda worked, but screwed the thumbnail generation.
