Intermittent 415 Unsupported Media Type on curl post uploads

I’m uploading a huge repository of images via curl upload using a post with file contents and i get intermittent 415 issues around 40% of the time, but the exact same file and upload works the rest of the time, so i’m finding it very hard to debug why this would be happening?

Is there a throttle on uploads or is something happening to the file data between the curl and cloudflare that’s confusing cloudflare?

I may just factor the errors in and try uploads multiple times till they “stick”.

To clarify: you see random 415, but errors are not reproducible, since next attempt works fine?

Yep, rough 40% fail, so sometimes it takes 2 attempts, but the request/post is exactly the same each time

Interesting.
I’m trying to dissect the issue, can you try batch API for upload and check if this changes anything?

Also do you use http2 or http1.1, keep alive?

using wp_remote_post for curl as its a wordpress site with associated attachments, appears to still be happening with keep-alive and http2 or 1.1, will try via php curl to see if that makes a difference.

Appeared to be related to wp_remote_post this method is working now:

<? $posttocurl = array('file'=> file_get_contents($fileName),'id' => $imageid); $ch = curl_init('https://api.cloudflare.com/client/v4/accounts/***/images/v1'); // Initialise cURL $authorization = "Authorization: Bearer ***"; // Prepare the authorisation token curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data' , $authorization )); // Inject the token into the header curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, 1); // Specify the request method as POST curl_setopt($ch, CURLOPT_POSTFIELDS, $posttocurl); // Set the posted fields curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // This will follow any redirects $result = curl_exec($ch); // Execute the cURL statement curl_close($ch); // Close the cURL connection $resultjson = json_decode($result);?>
<?

print_r($resultjson);
?>

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