Answers for "how to upload multiple images using guzzle"

0

how to upload multiple images using guzzle

$output = [];
        foreach ($request->images as $image ) {
    
            $output[] = [
            'name'     => 'image[]',
            'contents' => fopen( $image->getPathname(), 'r' ),
            'filename' => $image->getClientOriginalName()
            ]; 
        }

        $output [] =
            [
                'name'     => 'product_name',
                'contents' => \request()->get( 'name' )
            ];

        $output [] = [
            'name'     => 'cateogry',
            'contents' => \request()->get( 'category_id' )
        ];
        $output [] = [
            'name'     => 'subcategory',
            'contents' => \request()->get( 'sub_category_id' )
        ];


        $token    = session()->get('token');

        $client = new Client( [
            'base_uri' => "http://000.000.00.00:9000/",
        ]);

        $response = $client->request( 'POST', 'api/vendor/products', [
            'headers'  => ['Authorization' => 'Bearer'.$token],
            'multipart'=> $output
        ]);
        
        $data = \GuzzleHttp\json_decode($response->getBody());
Posted by: Guest on August-15-2021

Browse Popular Code Answers by Language