You can use this code to send file using curl. Make sure you use CURLFile class.
$file = $request->file('file');
$file_name = $file->getClientOriginalName();
$file_ext = $file->getClientOriginalExtension();
$file_path = $file->getRealPath();
$fileName = request('fileName');
$curl_file = new CURLFile($file_path, $file_ext, $file_name);
$post_data = array(
'files' => $curl_file,
'name' => $fileName
);
$target_url = env('URL', null) . "/library";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $target_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content_Type: application/json',
'Authorization: Bearer ' . $_SESSION["token"],
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$response = curl_exec($ch);
curl_close($ch);
$contents = $response;
$content = json_decode($contents, true);
return response()->json(["status" => "ok"]);