Cloudflare Upload Images: Upload via URL (PHP CURL) Error!

Hi, I was using this PHP CURL in the documentation /Cloudflare-images-upload-an-image-via-url and It got an error of {“success”:false,“errors”:[{“code”:9106,“message”:“Missing X-Auth-Key, X-Auth-Email or Authorization headers”}]}

I tried add this Authorization headers and it returns ERROR 5400: Bad request: failed to decode metadata EOF while parsing a value at line 1 column 0

This is the code I used

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/images/v1",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"metadata\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"requireSignedURLs\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"url\"\r\n\r\n[\"https://sampledomain.com/SAMPLEIMAGE.png?ver=1\"]\r\n-----011000010111000001101001--\r\n\r\n",
  CURLOPT_HTTPHEADER => [
    "Content-Type: multipart/form-data; boundary=---011000010111000001101001",
    "X-Auth-Email: ".$X_Auth_Email,
    "Authorization: Bearer ".$X_Auth_Key,
  ],
]);

$response1 = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response1;
}

This topic was automatically closed after 12 days. New replies are no longer allowed.