I am trying to send my form data from one domain to another domain using API with Guzzle HTTP. But when I am sending any file field that time it gives me error.
My First server Code
$inputs = $request->all();
$scan_2 = 'user_scan_2_' . $request->file('fileToUpload')->getClientOriginalExtension();
$destination = base_path() . '/public/files/uploaded/user/temp/';
$request->file('fileToUpload')->move($destination, $scan_2);
$inputs['fileToUpload'] = $this->makeCurlFile($destination.'/'.$scan_2);
$response = Http::post('"http://msite.test/api/test', $inputs,$headers);
My Guzzle Code Over HTTP facade
public function send($method, $url, $data, $headers = ["Content-Type" => "application/json"]) {
$method = strtoupper($method);
$contentType = $headers['Content-Type'] ?? ($headers['content-type'] ?? '');
$requestData['headers'] = $headers;
if(in_array($method, ['GET', 'DELETE'])){
$requestData['query'] = $data;
}elseif(in_array($method, ['POST','PUT', 'PATCH'])){
switch(strtolower($contentType)){
case 'application/json':
$requestData['json'] = $data;
break;
case 'application/x-www-form-urlencoded':
$requestData['form_params'] = $data;
break;
case 'multipart/form-data':
$requestData['multipart'] = $data;
break;
default:
$requestData['body'] = $data;
break;
}
}
$response = $this->client->request($method, $url, $requestData);
return $response;
}
I am using content type as multipart/form-data Now when I run my code that time got error
Argument 2 passed to GuzzleHttp\Psr7\MultipartStream::addElement() must be of the type array, string given, called in
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire