Dhaval_patel's avatar

Base64 encode image uploading

Is this a correct way to upload base64 encoded image using Guzzle client?

$response = $this->client->post($uriBase,[
            'multipart' => [
                'name'     => 'image',
                'contents' => ['image'=>$base64]
            ]
      ]);
0 likes
2 replies
tykus's avatar

If the image is base64 encoded already, then why multipart at all?

Dhaval_patel's avatar

@tykus I am using face recognition and I need to pass base 64 encoded image

    $path ='https://upload.wikimedia.org/wikipedia/commons/3/37/Dagestani_man_and_woman.jpg';
        $type = pathinfo($path, PATHINFO_EXTENSION);
        $data = file_get_contents($path);
        $base64 = 'data:image/' . 'jpg' . ';base64,' . base64_encode($data);
        $response = $this->client->post($uriBase,[
            'headers'=>['Authorization' => 'Bearer '. $request->token],
            'form_params'=>['image' => $base64]
      ]);

But that is throwing exception of 400 Bad Request So I tried to upload image using multipart Let me know what would be the best way to solve that exception

I am using this API documentation https://developer.bioid.com/bwsreference/web-api/web-upload-api

Please or to participate in this conversation.