Laravel HttpClient Guzzle. Images and Array not sending at same time. 'A 'contents' key is required

204 views Asked by At
//These Images
    for($i = 0 ; $i < count($request['images']); $i++)
    {
        $response = $response->attach('images['.$i.']', file_get_contents($request['images'][$i]), 'image.png' );
    }
    $response = $response->post('...WEB_URL_HIDDEN.../api/merchant/createDeal', [
        'name' => 'name',
        'discount' => $request->discount,
        'type' => $request->type,
        'category' => $request->category,
        'actual_price' => $request->actual_price,
        'price' => $request->price,
        'after_discount' => $request->after_discount,
        'expiry' => $request->expiry,
        'description' => $request->description,

        // //These Arrays
        'branches' => $request['branches'],
        'tags' => $request['tags'],
    ]);
    dd($response->json());

This is my code for sending some images and aome data to an external API. I am sending images in attach() function and sending arrays down there called 'branches' and 'tags'. Now the problem is this that when I submit an error comes as:

" A 'contents' key is required ".

If I comment out attach() then it works well but images do not uploaded. And if a comment out 'branches' and 'tags' arrays then everything works find but arrays do not send to API. In a nutshell, the problem is the trade off between images and arrays.

0

There are 0 answers