Why Cloudflare R2 is the Future of Object Storage
Traditional cloud providers charge hefty egress fees every time your users stream video or load high-res photography. Cloudflare R2 changes the game with $0 egress fees and global Anycast edge routing.
Direct Presigned S3-Compatible Uploads
Instead of routing multi-megabyte payloads through your serverless API routes, issue short-lived presigned URLs:
import { PutObjectCommand } from '@aws-sdk/client-s3';
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
export async function generateUploadUrl(key, contentType) {
const command = new PutObjectCommand({
Bucket: process.env.CLOUDFLARE_R2_BUCKET_NAME,
Key: key,
ContentType: contentType,
});
return await getSignedUrl(s3Client, command, { expiresIn: 300 });
}
This delivers ultra-fast uploads straight from the browser to Cloudflare's nearest edge data center.
