Direct creator uploads

I have a form on my site where the user selects Video .mp4 from his local machine and clicks on Submit and then upon submit I want to upload that video in my Cloudflare account. For this I am going with Direct creator uploads >> Generate a unique one-time upload URL >> direct_upload way. Here is my code and just for security reasons, I removed my account details from code like key, email, token.

I am getting the following response:

{“success”:false,“errors”:[{“code”:10000,“message”:“Authentication error”}]}

Here is code:

<?php $cloudflare_api_key = '' ; $cloudflare_api_email = '' ; $cloudflare_api_token = '' ; $cloudflare_api_post_url = 'https://api.cloudflare.com/client/v4/accounts/$cloudflare_api_key/stream/direct_upload' ; $ch = curl_init(); //init curl curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'X-Auth-Email: '.$cloudflare_api_email.'', 'X-Auth-Key: '.$cloudflare_api_key.'', 'Authorization: Bearer'.$cloudflare_api_token.'', 'maxDurationSeconds: 3600', 'Content-Type:application/json', 'purge_everything: true' )); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/1.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0'); //setting our user agent curl_setopt($ch, CURLOPT_URL, $cloudflare_api_post_url); //setting our api post url curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); // call return content curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); //navigate the endpoint curl_setopt($ch, CURLOPT_POST, true); //set as post $response = curl_exec($ch); // start curl navigation print_r($response); //print response ?>

Here is Code Picture:

I’m not sure why you would use Auth Key and Bearer token at the same time. Try just using one or the other (which ever one you have a value for).

1 Like

Yes, please try passing only the auth key/email or bearer token; not both.

1 Like

Ah, yes. Bearer Tokens don’t require an email address.

Thanks for your response. When I delete any parameter from these 3 then I am getting the following return error.

{“success”:false,“errors”:[{“code”:9106,“message”:“Missing X-Auth-Key, X-Auth-Email or Authorization headers”}]}

If I keep (X-Auth-Key and X-Auth-Email) then getting the same
{“success”:false,“errors”:[{“code”:10000,“message”:“Authentication error”}]} error.