I want to upload file to another server with API in a Laravel project. I already use postman and that API works! In Laravel project I can upload file to my server but I want to upload that file to another server with API.
$api_key = $_COOKIE['api_key_supplier'];
$pic = $request->file('file');
try {
$client = new Client(); //GuzzleHttp\Client
$response = $client->post($this->sub_url . "up", [
'headers' => [
'Authorization' => "$api_key"
],
'form_params' => [
"filedata" => $pic,
"type" => 4,
]
]);
$res = \GuzzleHttp\json_decode($response->getBody(), true);
if ($response->getStatusCode() == 200)
return response()->json(['success' => 1, 'msg' => 'success']);
} catch (ClientException $e) {
return $e->getResponse()->getStatusCode();
}