I success when I use command to run
curl -X POST -F [email protected]/myFolder/pic.png -H "Authorization: Bearer tokenX" https://api.cloudflare.com/client/v4/accounts/{accountX}/images/v1
But when I use PHP to curl, code:
// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.cloudflare.com/client/v4/accounts/{accountX}/images/v1');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'file' => '@' .realpath('/myFolder/pic.png'));
$headers = array();
$headers[] = 'Authorization: Bearer tokenX';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
CF return error: ERROR 9422: Decode error: image failed to be decoded: Uploaded image must have image/jpeg or image/png content type
My file is png
and I can use curl command to post. What did I do wrong?