Subhan
CDCloudflare Developers
•Created by Subhan on 9/19/2023 in #workers-help
need to upload video on cloudflare stream using laravel
Hi need to upload video on cloudflare stream using laravel
My laravel code is:
public function handle()
{
try {
$authToken = env('AUTH_TOKEN_STREAM')
$apiEndpoint = env('API_ENDPOINT_STREAM')
$workouts = public_path('images/video.mp4');
$videoContents = fopen($workouts, 'rb');
//$videoContents = file_get_contents($workouts);
if ($videoContents !== false) {
echo "Uploading video: " . $workouts . "\n";
$response = Http::withHeaders([
'Authorization' => 'Bearer ' . $authToken,
])->attach('file', $videoContents, basename('video.mp4'))
->post($apiEndpoint);
print_r($response);
if ($response->successful()) {
print_r('==============================');
print_r($response->json()['result']['id']);
echo "\n";
}
}
$this->info('Images Uploaded on Cloudflare');
} catch (\Exception $e) {
print_r('Its in Catch Block');
echo "\n";
print_r('====================================');
$this->handle();
}
}
2 replies