File uploads work when I am using postman but when I am using CAKEPHP project (Http Client) for only data it’s work but with file not working
Cakephp Client : Only Data without File ( it’s working )
Cakephp Client : Data with File ( does not work )
Postman : Data with File ( it’s working )
in /config/routes.php
$routes->extensions(['json','xml']);
Code :
use CakeHttpClient;
use CakeHttpClientFormData;
public function add()
{
$client = $this->Clients->newEntity();
if ($this->request->is('post')) {
$client = $this->Clients->patchEntity($client, $this->request->data);
if ($this->Clients->save($client)) {
$formData = new FormData();
$formData->addMany($this->request->data);
$file = $formData->addFile('header_file',fopen($this->request->data['header_file']['tmp_name'], 'r'));
$file->contentId($this->request->data['header_file']['name']);
$file->disposition('attachment');
$options = [
'headers' => ['Content-Type' => $formData->contentType()]
];
$http = new Client();
$url = 'http://example.com/clients/add.json';
$result = $http->post($url,(string)$formData,$options);
var_dump($result);
exit;
}
}
Thanks, I use cakephp 3.3.9 sorry for bad English.