Need CDN script for R2 storage addition

Hi,
I plan to use cloudflare R2 for my storage and cloudflare CDN for my content delivery. I need CDN control script to setup my storage server. The service provider has a CDN for AWS S3 but not for Cloudflare R2. They have asked me to contact cloudflare. Where can I get the CDN script?

Attached the CDN scrit for AWS s3 for reference


<?php // CDN API for Amazon Web Services S3 storage // specify your API key and API Secret in this file, same values that you use in admin panel // if you don't have them stored anywhere, you can create another pair in AWS -> -> Security credentials menu define('AWS_API_KEY', ''); define('AWS_API_SECRET', ''); define('AWS_LINK_VALID_MINUTES', 60); function cdnapi_aws_test($streaming_key) { // return success by default return null; } function cdnapi_aws_get_video($file_path, $file_url, $start_str, $limit, $streaming_key) { global $config; if (!is_file("$config[project_path]/admin/data/system/aws.phar")) { return $file_url; } require_once "$config[project_path]/admin/data/system/aws.phar"; try { $url_parsed = explode('.', parse_url($file_url, PHP_URL_HOST)); if ($url_parsed[1] == 's3') { $s3 = new Aws\S3\S3Client([ 'version' => 'latest', 'region' => $url_parsed[2], 'credentials' => [ 'key' => AWS_API_KEY, 'secret' => AWS_API_SECRET, ] ]); $cmd = $s3->getCommand('GetObject', [ 'Bucket' => $url_parsed[0], 'Key' => trim($file_path, '/') ]); $request = $s3->createPresignedRequest($cmd, '+' . intval(AWS_LINK_VALID_MINUTES) . ' minutes'); return (string) $request->getUri(); } } catch (Throwable $ignored) { } return $file_url; } function cdnapi_aws_head_video($file_path, $file_url, $start_str, $limit, $streaming_key) { global $config; if (!is_file("$config[project_path]/admin/data/system/aws.phar")) { return $file_url; } require_once "$config[project_path]/admin/data/system/aws.phar"; try { $url_parsed = explode('.', parse_url($file_url, PHP_URL_HOST)); if ($url_parsed[1] == 's3') { $s3 = new Aws\S3\S3Client([ 'version' => 'latest', 'region' => $url_parsed[2], 'credentials' => [ 'key' => AWS_API_KEY, 'secret' => AWS_API_SECRET, ] ]); $cmd = $s3->getCommand('HeadObject', [ 'Bucket' => $url_parsed[0], 'Key' => trim($file_path, '/') ]); $request = $s3->createPresignedRequest($cmd, '+' . intval(AWS_LINK_VALID_MINUTES) . ' minutes'); return (string) $request->getUri(); } } catch (Throwable $ignored) { } return $file_url; } function cdnapi_aws_get_image($file_path, $file_url, $streaming_key) { global $config; if (!is_file("$config[project_path]/admin/data/system/aws.phar")) { return $file_url; } require_once "$config[project_path]/admin/data/system/aws.phar"; try { $url_parsed = explode('.', parse_url($file_url, PHP_URL_HOST)); if ($url_parsed[1] == 's3') { $s3 = new Aws\S3\S3Client([ 'version' => 'latest', 'region' => $url_parsed[2], 'credentials' => [ 'key' => AWS_API_KEY, 'secret' => AWS_API_SECRET, ] ]); $cmd = $s3->getCommand('GetObject', [ 'Bucket' => $url_parsed[0], 'Key' => trim($file_path, '/') ]); $request = $s3->createPresignedRequest($cmd, '+' . intval(AWS_LINK_VALID_MINUTES) . ' minutes'); return (string) $request->getUri(); } } catch (Throwable $ignored) { } return $file_url; } function cdnapi_aws_head_image($file_path, $file_url, $streaming_key) { global $config; if (!is_file("$config[project_path]/admin/data/system/aws.phar")) { return $file_url; } require_once "$config[project_path]/admin/data/system/aws.phar"; try { $url_parsed = explode('.', parse_url($file_url, PHP_URL_HOST)); if ($url_parsed[1] == 's3') { $s3 = new Aws\S3\S3Client([ 'version' => 'latest', 'region' => $url_parsed[2], 'credentials' => [ 'key' => AWS_API_KEY, 'secret' => AWS_API_SECRET, ] ]); $cmd = $s3->getCommand('HeadObject', [ 'Bucket' => $url_parsed[0], 'Key' => trim($file_path, '/') ]); $request = $s3->createPresignedRequest($cmd, '+' . intval(AWS_LINK_VALID_MINUTES) . ' minutes'); return (string) $request->getUri(); } } catch (Throwable $ignored) { } return $file_url; } function cdnapi_aws_invalidate_resources($server_url, $folders, $files, $operation) { // not needed for AWS S3 }

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