public function constructMultipartOptions(array $data, array $multipart_data): array
    {
        $builder = new Builder();
        $this->logger->debug('Creating multi-part form array data (complex and expensive)');
        foreach ($data as $id => $value) {
              if (array_key_exists($id,$multipart_data)) {
                $data = new MultipartData(
                    (string) $multipart_data[$id]['id'],
                    stream_get_contents($multipart_data[$id]['stream']),
                    pathinfo($multipart_data[$id]['filename'], PATHINFO_BASENAME)
                );
                $builder->append($data);
            } elseif($id=='mediagroup') {
               foreach($multipart_data as $ii => $mdata){
                $data = new MultipartData(
                    pathinfo($mdata['filename'], PATHINFO_BASENAME),
                    stream_get_contents($mdata['stream']),
                    pathinfo($mdata['filename'], PATHINFO_BASENAME)
                );
                $builder->append($data);
               }
            } else {
                $data = new MultipartData((string) $id, (string) $value);
                $builder->append($data);
            }
        }

        $body = $builder->buildAll();
        $array = [
            'headers' => [
                'Content-Type' => 'multipart/form-data; boundary="' . $builder->getBoundary() . '"',
                'Content-Length' => \strlen($body)
            ],
            'body' => $body
        ];
        return $array;
    }