Image is not populating properly in field collection

Hi,

Following problem is coming when i am uploading images in field collection–

  1. When i am uploading images in asset folder this listener is calling { name: kernel.event_listener, event: pimcore.asset.postAdd, method: onPostAdd } . on this method i am matching the id and adding the images in field which type is field collection. but the images is not being add properly…some images being skip sometimes…i am adding new data with old data and than looping the final data…this being fail when i am uploading more than 1 images sequentially…when i am uploading single images and zip folder than its working fine…

    $items = new \Pimcore\Model\DataObject\Fieldcollection();
    
         foreach ($oldData as $val) {
             $item = new DataObject\Fieldcollection\Data\Image);
             $item->setImage($val);
             $items->add($item);
         }
         $obj->setImages($items);