Developer Platform Developer Platform Developer Platform Cơ bản Entry កម្រិតចាប់ផ្តើម ~7 phút đọc · ~747 từ ~7 min read · ~637 words

R2 là gì? Lưu file trên Cloudflare mà không “sợ” phí egress What is R2? Object storage on Cloudflare without egress sticker shock What is R2? Object storage on Cloudflare without egress sticker shock

R2 là kho object trên Cloudflare — giống S3 nhưng không tính phí egress khi phục vụ qua mạng Cloudflare. Hợp ảnh user, backup, và file tĩnh cho Workers/Pages. R2 is Cloudflare object storage — S3-like but without egress fees when served through Cloudflare’s network. Great for user images, backups, and static files for Workers/Pages. R2 is Cloudflare object storage — S3-like but without egress fees when served through Cloudflare’s network. Great for user images, backups, and static files for Workers/Pages.

Use Case 1: Secure User Uploads to R2 via Signed URLs

Lưu nội dung do người dùng tạo Storing user generated content Storing user generated content

Lưu nội dung do người dùng tạo (UGC) trên R2 — kiến trúc nhanh, an toàn, chi phí hợp lý. Store user-generated content in R2 for fast, secure, and cost-effective architecture. Store user-generated content in R2 for fast, secure, and cost-effective architecture.

Thuật ngữ: Concepts: Concepts: R2 · Workers · UGC · Object storage

Sơ đồ chính thức ↗ Official diagram ↗ Official diagram ↗ · Lưu trữ Storage Storage

Object storage là gì — và vì sao không chỉ dùng ổ đĩa hosting? What is object storage — and why not only a hosting disk? What is object storage — and why not only a hosting disk?

Hosting truyền thống thường gắn ổ đĩa với một máy chủ: dung lượng có hạn, backup và scale khó khi traffic tăng. Object storage (như R2) lưu file dưới dạng object có key — ảnh.png, backup/2026-08.zip — trong bucket, truy cập qua API HTTP(S), scale độc lập với app server. Traditional hosting ties disk space to one server: limited capacity, harder backup and scale when traffic grows. Object storage (like R2) stores files as keyed objects — image.png, backup/2026-08.zip — in a bucket, accessed via HTTP(S) APIs, scaling separately from your app server. Traditional hosting ties disk space to one server: limited capacity, harder backup and scale when traffic grows. Object storage (like R2) stores files as keyed objects — image.png, backup/2026-08.zip — in a bucket, accessed via HTTP(S) APIs, scaling separately from your app server.

R2 tương thích API kiểu S3: nhiều công cụ và SDK quen thuộc. Khác biệt nổi bật trên blog.cloudflare.com về storage: không tính phí egress (tải dữ liệu ra) khi phục vụ qua mạng Cloudflare — tránh “hóa đơn bất ngờ” khi ảnh viral. R2 speaks S3-compatible APIs: familiar tools and SDKs. A standout difference in Cloudflare Blog storage posts: no egress fees when serving through Cloudflare’s network — avoiding “surprise bills” when an image goes viral. R2 speaks S3-compatible APIs: familiar tools and SDKs. A standout difference in Cloudflare Blog storage posts: no egress fees when serving through Cloudflare’s network — avoiding “surprise bills” when an image goes viral.

Use case điển hình: ảnh upload user, video ngắn, export backup database, static asset cho site, log archive. Không phù hợp thay database quan hệ — dùng D1 hoặc DB chuyên dụng cho dữ liệu có cấu trúc và query phức tạp. Typical uses: user uploads, short video, database backup exports, site static assets, log archives. Not a replacement for relational databases — use D1 or a dedicated DB for structured data and complex queries. Typical uses: user uploads, short video, database backup exports, site static assets, log archives. Not a replacement for relational databases — use D1 or a dedicated DB for structured data and complex queries.

Use Case 1: Secure User Uploads to R2 via Signed URLs

Lưu nội dung do người dùng tạo Storing user generated content Storing user generated content

Lưu nội dung do người dùng tạo (UGC) trên R2 — kiến trúc nhanh, an toàn, chi phí hợp lý. Store user-generated content in R2 for fast, secure, and cost-effective architecture. Store user-generated content in R2 for fast, secure, and cost-effective architecture.

Thuật ngữ: Concepts: Concepts: R2 · Workers · UGC · Object storage

Sơ đồ chính thức ↗ Official diagram ↗ Official diagram ↗ · Lưu trữ Storage Storage

Egress là gì — và R2 giúp gì cho ví tiền? What is egress — and how does R2 help your budget? What is egress — and how does R2 help your budget?

Egress là lưu lượng dữ liệu “ra khỏi” nhà cung cấp cloud khi user tải file. Một số nhà cung cấp object storage giá storage rẻ nhưng egress đắt — site càng nổi tiếng, bill càng leo. R2 được thiết kế với mô hình: trả cho storage và operation, không phạt egress qua Cloudflare. Egress is data leaving a cloud provider when users download files. Some object stores price storage cheaply but egress expensively — the more popular the site, the higher the bill. R2 is designed around paying for storage and operations, not punishing egress through Cloudflare. Egress is data leaving a cloud provider when users download files. Some object stores price storage cheaply but egress expensively — the more popular the site, the higher the bill. R2 is designed around paying for storage and operations, not punishing egress through Cloudflare.

Lưu ý thực tế: egress-free áp dụng khi bạn phục vụ qua Workers, CDN, hoặc các đường tích hợp Cloudflare — không phải “mọi cách tải từ Internet đều miễn phí mãi mãi”. Đọc pricing và docs trước khi thiết kế kiến trúc tải file trực tiếp từ R2 public bucket ra ngoài mạng CF. Reality check: zero egress applies when you serve via Workers, CDN, or Cloudflare-integrated paths — not “every possible Internet download is free forever.” Read pricing and docs before designing direct public-bucket downloads outside the CF network. Reality check: zero egress applies when you serve via Workers, CDN, or Cloudflare-integrated paths — not “every possible Internet download is free forever.” Read pricing and docs before designing direct public-bucket downloads outside the CF network.

So với giữ ảnh trên cùng VPS chạy WordPress: R2 tách storage khỏi compute — VPS restart không làm mất file; scale CDN/Worker không cần copy ảnh sang máy mới. Phù hợp lộ trình Developer Platform trên hub. Vs keeping images on the same VPS running WordPress: R2 separates storage from compute — VPS restarts do not wipe files; scaling CDN/Workers does not require copying images to new machines. Fits the Developer Platform track on this hub. Vs keeping images on the same VPS running WordPress: R2 separates storage from compute — VPS restarts do not wipe files; scaling CDN/Workers does not require copying images to new machines. Fits the Developer Platform track on this hub.

Hình 1: Cloudflare Image Resizing and R2

Tối ưu phân phối ảnh với Image Resizing và R2 Optimizing image delivery with Cloudflare image resizing and R2 Optimizing image delivery with Cloudflare image resizing and R2

Giải pháp tối ưu phân phối ảnh, mở rộng được và hiệu năng cao — Image Resizing kết hợp R2. Learn how to get a scalable, high-performance solution to optimizing image delivery. Learn how to get a scalable, high-performance solution to optimizing image delivery.

Thuật ngữ: Concepts: Concepts: Image Resizing · R2 · Transformations · Cache

Sơ đồ chính thức ↗ Official diagram ↗ Official diagram ↗ · Phân phối nội dung Content Delivery Content Delivery

Gắn R2 với Workers — binding thay vì hard-code key Attach R2 to Workers — bindings instead of hard-coded keys Attach R2 to Workers — bindings instead of hard-coded keys

Trong wrangler.toml hoặc dashboard, bạn khai báo binding R2 (ví dụ MY_BUCKET) gắn với bucket. Worker gọi env.MY_BUCKET.put(key, file) hoặc .get(key) — credential do platform inject, không nằm trong source frontend. In wrangler.toml or the dashboard, declare an R2 binding (e.g. MY_BUCKET) tied to a bucket. The Worker calls env.MY_BUCKET.put(key, file) or .get(key) — credentials are injected by the platform, not in frontend source. In wrangler.toml or the dashboard, declare an R2 binding (e.g. MY_BUCKET) tied to a bucket. The Worker calls env.MY_BUCKET.put(key, file) or .get(key) — credentials are injected by the platform, not in frontend source.

Pattern upload an toàn: browser gửi file tới Worker (hoặc presigned URL ngắn hạn do Worker cấp) → Worker validate loại file/kích thước → put R2 → trả URL public hoặc signed. Không expose secret S3 key trong JavaScript client. Safer upload pattern: browser sends file to Worker (or a short-lived presigned URL from Worker) → Worker validates type/size → put to R2 → return public or signed URL. Never expose S3 secrets in client JavaScript. Safer upload pattern: browser sends file to Worker (or a short-lived presigned URL from Worker) → Worker validates type/size → put to R2 → return public or signed URL. Never expose S3 secrets in client JavaScript.

Kết hợp Image Resizing hoặc CDN: lưu bản gốc trên R2, phục vụ biến thể resize qua Cloudflare — giảm bandwidth và tăng tốc mobile. Bài CDN trên hub giải thích cache; R2 giải thích “file gốc nằm ở đâu”. Combine Image Resizing or CDN: store originals on R2, serve resized variants through Cloudflare — less bandwidth, faster mobile. The CDN post on this hub explains cache; R2 explains “where the original file lives.” Combine Image Resizing or CDN: store originals on R2, serve resized variants through Cloudflare — less bandwidth, faster mobile. The CDN post on this hub explains cache; R2 explains “where the original file lives.”

Pages có thể đọc static từ build output; R2 cho nội dung động user tạo. Nhiều app full-stack: Pages UI + Worker API + R2 storage — xem diagram fullstack trên hub. Pages can serve static build output; R2 holds dynamic user-generated content. Many full-stack apps: Pages UI + Worker API + R2 storage — see the fullstack diagram on this hub. Pages can serve static build output; R2 holds dynamic user-generated content. Many full-stack apps: Pages UI + Worker API + R2 storage — see the fullstack diagram on this hub.

Bắt đầu tuần đầu — và lỗi thường gặp Your first week — and common mistakes Your first week — and common mistakes

Tuần 1: tạo bucket test; upload vài file qua dashboard hoặc wrangler; viết Worker GET trả một object; thử public access vs private + signed URL. Đọc docs lifecycle nếu cần xóa log cũ tự động. Week 1: create a test bucket; upload files via dashboard or wrangler; write a GET Worker returning one object; try public access vs private plus signed URLs. Read lifecycle docs if you need automatic old-log deletion. Week 1: create a test bucket; upload files via dashboard or wrangler; write a GET Worker returning one object; try public access vs private plus signed URLs. Read lifecycle docs if you need automatic old-log deletion.

Lỗi phổ biến: bucket public toàn bộ — lộ file nhạy cảm; không giới hạn kích thước upload — bị spam; quên CORS khi frontend gọi trực tiếp; nhầm R2 thay SQL. Sao lưu: R2 không thay chiến lược backup ứng dụng — vẫn cần versioning hoặc export định kỳ. Common mistakes: fully public buckets leaking sensitive files; no upload size limits — spam abuse; missing CORS for direct frontend calls; treating R2 as SQL. Backups: R2 does not replace app backup strategy — still version or export on a schedule. Common mistakes: fully public buckets leaking sensitive files; no upload size limits — spam abuse; missing CORS for direct frontend calls; treating R2 as SQL. Backups: R2 does not replace app backup strategy — still version or export on a schedule.

Tiếp theo: bài Pages vs Workers, Developer Platform overview, use case build serverless app. Một demo upload avatar nhỏ học R2 nhanh hơn đọc mười trang pricing. Next: Pages vs Workers post, Developer Platform overview, build-serverless-app use case. A tiny avatar-upload demo teaches R2 faster than ten pages of pricing. Next: Pages vs Workers post, Developer Platform overview, build-serverless-app use case. A tiny avatar-upload demo teaches R2 faster than ten pages of pricing.

Câu hỏi thường gặp Frequently asked questions Frequently asked questions

R2 có thay hosting WordPress không? Can R2 replace WordPress hosting? Can R2 replace WordPress hosting?

Không trực tiếp. WordPress cần PHP và database trên server. R2 phù hợp lưu media, backup, hoặc static asset — kết hợp với hosting/Worker xử lý logic. Not directly. WordPress needs PHP and a database on a server. R2 fits media, backups, or static assets — combined with hosting or Workers for logic. Not directly. WordPress needs PHP and a database on a server. R2 fits media, backups, or static assets — combined with hosting or Workers for logic.

File trên R2 có tự cache CDN không? Are R2 files automatically CDN-cached? Are R2 files automatically CDN-cached?

Khi bạn phục vụ qua Worker hoặc custom domain gắn Cloudflare với cache rule phù hợp, có thể cache edge. Bucket private + signed URL thì cache phức tạp hơn — thiết kế cố ý. When served through a Worker or a Cloudflare custom domain with sensible cache rules, edge cache is possible. Private buckets plus signed URLs make caching trickier — design intentionally. When served through a Worker or a Cloudflare custom domain with sensible cache rules, edge cache is possible. Private buckets plus signed URLs make caching trickier — design intentionally.

R2 và S3 khác nhau chính ở đâu cho người mới? What is the main R2 vs S3 difference for beginners? What is the main R2 vs S3 difference for beginners?

API tương thích S3 nhưng R2 nằm trong ecosystem Cloudflare (bindings, zero egress qua CF). Nếu bạn đã dùng Workers/Pages, R2 thường ít ma sát hơn mang thêm một nhà cung cấp riêng. S3-compatible API but R2 lives in Cloudflare’s ecosystem (bindings, zero egress via CF). If you already use Workers/Pages, R2 usually adds less friction than another separate vendor. S3-compatible API but R2 lives in Cloudflare’s ecosystem (bindings, zero egress via CF). If you already use Workers/Pages, R2 usually adds less friction than another separate vendor.

Học tiếp trên hub (on-page backlinks) Keep learning on this hub (on-page links) Keep learning on this hub (on-page links)

Nguồn tham khảo (blog.cloudflare.com) Sources (blog.cloudflare.com) Sources (blog.cloudflare.com)

Nội dung được viết lại để dễ hiểu hơn; luôn đọc bài gốc trên blog.cloudflare.com và docs chính thức khi cần chi tiết kỹ thuật hoặc cập nhật mới nhất. Content is rewritten for clarity; always read the original posts on blog.cloudflare.com and official docs for technical detail or the latest updates. Content is rewritten for clarity; always read the original posts on blog.cloudflare.com and official docs for technical detail or the latest updates.

Cloudflare Developer Platform: build global apps without managing servers yourself
Developer Platform Developer Platform Developer Platform Trung cấp Intermediate កម្រិតមធ្យម ~9 phút ~9 min ~9 នាទី

Cloudflare Developer Platform: xây ứng dụng toàn cầu mà không tự quản lý server Cloudflare Developer Platform: build global apps without managing servers yourself Cloudflare Developer Platform: build global apps without managing servers yourself

Developer Platform giống bộ lego edge: compute (Workers), hộp đựng (R2/KV/D1), AI, và lớp bảo vệ — lắp theo use case thay vì mua cả trung tâm dữ liệu. The Developer Platform is like an edge Lego set: compute (Workers), storage boxes (R2/KV/D1), AI, and protection layers — assemble by use case instead of buying a whole data center. The Developer Platform is like an edge Lego set: compute (Workers), storage boxes (R2/KV/D1), AI, and protection layers — assemble by use case instead of buying a whole data center.

Đọc bài → Read post → អានអត្ថបទ →

What are Cloudflare Workers? Serverless at the edge, explained simply
Workers Workers Workers Cơ bản Entry កម្រិតចាប់ផ្តើម ~7 phút ~7 min ~7 នាទី

Cloudflare Workers là gì? Serverless ở “mép mạng” giải thích đơn giản What are Cloudflare Workers? Serverless at the edge, explained simply What are Cloudflare Workers? Serverless at the edge, explained simply

Workers giống thuê “người trực” ngay gần khách hàng: nhận request, xử lý nhanh, trả kết quả — bạn không phải tự mua và bảo trì cả tòa nhà server. Workers are like stationing helpers near customers: take a request, handle it quickly, return a result — without buying and maintaining a whole server building. Workers are like stationing helpers near customers: take a request, handle it quickly, return a result — without buying and maintaining a whole server building.

Đọc bài → Read post → អានអត្ថបទ →

Pages vs Workers: when to use which?
Workers Workers Workers Cơ bản Entry កម្រិតចាប់ផ្តើម ~7 phút ~7 min ~7 នាទី

Pages và Workers: khi nào dùng cái nào? Pages vs Workers: when to use which? Pages vs Workers: when to use which?

Pages thuận tiện deploy site tĩnh và frontend; Workers chạy code xử lý request tùy ý. Nhiều app hiện đại: Pages làm “mặt tiền”, Workers làm API và logic phía sau. Pages is great for static sites and frontends; Workers runs custom request-handling code. Many modern apps: Pages as the storefront, Workers as APIs and backend logic. Pages is great for static sites and frontends; Workers runs custom request-handling code. Many modern apps: Pages as the storefront, Workers as APIs and backend logic.

Đọc bài → Read post → អានអត្ថបទ →

Xem tất cả bài blog Browse all blog posts Browse all blog posts

Chuỗi bài AI · Security · CDN · Workers · Developer Platform — viết lại cho người mới và trung cấp. AI · Security · CDN · Workers · Developer Platform — rewritten for entry and intermediate learners. AI · Security · CDN · Workers · Developer Platform — rewritten for entry and intermediate learners.