Uploading files via php

Hi team,

I am currently using YII2 and would like to upload my videos to cloud flare but unable to get any resources on these.

Kindly assist

Are you referring to https://www.cloudflare.com/products/cloudflare-stream/?

Hi Sandro, yes I would like to upload my videos for straming

It all is explained at https://developers.cloudflare.com/stream/getting-started/

As for a PHP client, you could probably use https://github.com/ankitpokhrel/tus-php

I have tried the same but seems not compatible to yii2

It should be, it is a regular PHP library. If you encounter issues I would suggest you contact either the developers of YII2 or of the TUS client.

Ok, one last question. are the videos stored in cloudflare or will be stored in my bucket and cloudflare just used as a steaming service?

They are stored with Cloudflare.

How can I locate my account ID?

A final one I am getting this error

{ “result”: null, “success”: false, “errors”: [ { “code”: 10004, “message”: “Decoding Error” } ], “messages”: null }

is there an issue with my domain?

The ID is also covered at https://developers.cloudflare.com/stream/getting-started/uploading-command-line/

As for the error, if you didnt specify the right ID I guess that is what is to be expected.

Hi I have specified the correct Client ID but still facing experiencing the same error. I am using curl to upload is there a specific aspect that I have done wrong?

here is my sample code

$file_path = $_FILES['file']['tmp_name'];
$file_name = $_FILES['file']['name'];
$file_type = $_FILES['file']['type'];
$file_size = $_FILES['file']['size'];
$file_error = $_FILES['file']['error'];
$ch = curl_init(); //init curl
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
			 'X-Auth-Email: '.$cloudflare_api_email.'',
			 'X-Auth-Key: '.$cloudflare_api_key.'')
		);
curl_setopt(
$ch,
CURLOPT_POSTFIELDS,
array(
  'file' =>
      '@'. $_FILES['file']['tmp_name']
      . ';filename=' . $_FILES['file']['name']
));	
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
//curl_setopt($ch, CURLOPT_POSTFIELDS, $file_path); // set our $BODY
$response = curl_exec($ch); // start curl navigation
print_r($response); //print response
}

kindly assist

Without the error it is impossible to say anything.

This is the error

{ “result”: null, “success”: false, “errors”: [ { “code”: 10004, “message”: “Decoding Error” } ], “messages”: null }

You are using cURL, not the library I suggested yesterday. I am not sure Cloudflare would support that at all.

Thanks, the chat was not that helpful. Let me try and figure it out on my own

Hi Team,

I have managed to setup the tus. But when I try to upload I get this error

Message = Client error: POST https://api.cloudflare.com/files resulted in a 404 Not Found response:

404 Not Found

Maybe try modifying it for the official yii framework’s HTTP client?