Recently, I've been tinkering with cloudflare's r2 storage and also activated the chatgpt plus version, allowing chatgpt to write such an upload function.
Explanation: The vendor directory is using the AWS SDK for PHP installed via Composer.
Tutorial:#
You need to customize lines 7-11 and 29 in the r2.php file.
$accessKey = 'your-access-key';
$secretKey = 'your-secret-key';
$region = 'your-region';
$bucket = 'your-bucket-name';
$customDomain = 'your-url';
'endpoint' => 'https://storage.googleapis.com',
Let me explain to everyone below!
Open cloudflare r2 storage - Add a management R2API token
Pay attention to selecting the permission that can be edited.
Fill in the short one with $accessKey and the long one with $secretKey!
$bucket = Bucket name!
$customDomain = The custom domain you added to the bucket!
The twenty-ninth line is the API of the bucket
Note that the bucket name will be added after this link, just remove this name.
The uploaded files will be sorted by date, then the file name will be renamed and the complete link will be returned.
File download link: https://r2.k7blog.com/2023/03/19/6416142e8364e.gz