I can send a POST request successfully with POSTMAN and when I turn the request to code I get:
curl --location --request POST 'https://webservice.apiCommerce/import' \
--form 'id=1186' \
--form 'image=@/C:/collection/img/ecomm/01.jpg'
Now, I am trying the same thing with PHP curl and I don't get the expected result.
$imagePath = "./img/$fileName";
$post = [
"id" => $id,
"image" => '@'.$imagePath
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_URL, $url);
$response = curl_exec($ch);
$payload = json_decode($response, true);
The request gets sent, but the image doesn't get uploaded correctly. Is there a reason why there's a mismatch? I can't figure out what's wrong. I tried removing the header and so forth, but it doesn't seem to make any difference at all. I even hard-coded the img path and it doesn't seem to work.