1

When I use the terminal for posting an image using CURL it works fine but when I transform it within PHP code it throws an error 400 Bad Request.

CURL code using Terminal

curl -H "Authorization: Bearer ${access_token}" \
     -H "Content-Type: image/jpeg" \
     -i \
     -X POST \
     --data-binary @my_image.jpg \
     https://example.com/objects/v1/files

CURL code within PHP file

$headers = array(
   'Content-Type: image/jpeg',
   'Authorization: Bearer ' . $accessToken,    
);
$binary = 'my_image.jpg';
$ch = curl_init('https://example.com/objects/v1/files');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, '@'.$binary);

0 Answers0