'how to send a file from one web system to another using guzzle client in laravel

i want to send an image from one web system(A) to another web system(B).the image is saved in system(A) and then sent to system(B).am using guzzle http client to achieve this.my api in system (B) works very well as i have tested it in postman.the part i have not understood why its not working is in my system(A) where i have written the guzzle code.i have not seen any error in my system(A) log file but the file isnt sent to system (B).

here is my image save function is system(A).

 public function productSavePicture(Request $request)
{
    try {
        $validation = Validator::make($request->all(), [
            'product_id' => 'required',
        ]);

        $product_details = product::where('systemid', $request->product_id)->first();

        if ($request->hasfile('file')) {
            $file = $request->file('file');
            $extension = $file->getClientOriginalExtension(); // getting image extension
            $company_id = Auth::user()->staff->company_id;

            $filename = ('p' . sprintf("%010d", $product_details->id)) . '-m' . sprintf("%010d", $company_id) . rand(1000, 9999) . '.' . $extension;

            $product_id = $product_details->id;

            $this->check_location("/images/product/$product_id/");
            $file->move(public_path() . ("/images/product/$product_id/"), $filename);

            $this->check_location("/images/product/$product_id/thumb/");
            $thumb = new thumb();

            $dest = public_path() . "/images/product/$product_id/thumb/thumb_" . $filename;
            $thumb->createThumbnail(
                public_path() . "/images/product/$product_id/" . $filename,
                $dest,
                200);
            
            $systemid = $request->product_id;

            $product_details->photo_1 = $filename;
            $product_details->thumbnail_1 = 'thumb_' . $filename;
            $product_details->save();

            // push image to system(B)

            $imageinfo = array(
                'file' =>  $filename,
                'product_id'  =>  $product_details->id,
            );

            $client = new \GuzzleHttp\Client();
            $url = "http://systemb/api/push_h2image";
            $response = $client->request('POST',$url,[
                // 'Content-type' => 'multipart/form-data',
                'multipart' => [
                    [
                        'name'     => 'imagecontents',
                        'contents' => fopen(public_path() . ("/images/product/$product_id/") . $filename, 'r'),
                        // file_get_contents(public_path("/images/product/$product_id/thumb/thumb_" . $filename)),
                        'filename' =>$filename
                    ],

                    [
                        'name'     => 'imageinfo',
                        'contents' => json_encode($imageinfo)
                    ],
                ]
            ]);

        }

    }
}

i have followed every step in the documentation but still the process isnt working.where might i be making a wrong move?the laravel version of my project is 5.8 and the version of the guzzle http client is 7.4.1



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source