เพิ่มช่องทาง S3
เหมาะกับกรณีไหน
ใช้ช่องทาง S3 เมื่อ:
- ต้องการเชื่อมต่อ object storage service ที่รองรับ S3 เช่น Cloudflare R2, Backblaze B2, MinIO, AWS S3 หรือ provider อื่นที่ compatible
- ชอบรูปแบบการตั้งค่า S3 มาตรฐาน:
Endpoint, Access Key และ Secret Key - ไม่ต้องการใช้ช่องทาง native Cloudflare R2 binding หรือ storage provider ของคุณไม่ใช่ Cloudflare R2
สิ่งที่ต้องเตรียมก่อนเริ่ม
| ข้อกำหนด | วัตถุประสงค์ |
|---|---|
| S3 Endpoint | S3 API endpoint ของ object storage service |
| Bucket name | Bucket ที่จะใช้เก็บไฟล์ |
| Region | Storage region สำหรับ Cloudflare R2 มักเป็น auto |
| Access Key ID | S3 access key ID |
| Secret Access Key | S3 secret access key |
| CDN domain | Custom domain สำหรับการเข้าถึงไฟล์แบบไม่บังคับ |
ตัวอย่าง Cloudflare R2 ผ่าน S3 API:
text
Endpoint: https://your-account-id.r2.cloudflarestorage.com
Bucket: your-r2-bucket-name
Region: auto
Access Key ID: copied from the Cloudflare R2 API token
Secret Access Key: copied from the Cloudflare R2 API tokenเพิ่มได้จากที่ไหน
- เปิดการตั้งค่าระบบ
- ไปที่การตั้งค่าการอัปโหลด
- คลิกเพิ่มช่องทางที่มุมขวาบน
- เลือก
S3
รายละเอียดฟิลด์
| ฟิลด์ | ใช้ทำอะไร | จำเป็น |
|---|---|---|
| Channel name | ชื่อที่จำง่ายสำหรับช่องทาง S3 เช่น s3test หรือ R2-S3 | ใช่ |
| Enable channel | ควบคุมว่าช่องทางนี้จะเข้าร่วมการเลือกช่องทางอัปโหลดหรือไม่ | แนะนำ |
| Endpoint | S3 service endpoint แบบเต็ม รวม https:// | ใช่ |
| Custom CDN domain | ไม่บังคับ เมื่อใส่แล้ว file links ที่สร้างขึ้นจะเลือกใช้ domain นี้ก่อน | ไม่ |
| Bucket name | Bucket name เช่น s3test หรือ img-r2 | ใช่ |
| Bucket region | Region สำหรับ Cloudflare R2 มักเป็น auto | ใช่ |
| Access Key ID | S3 access key ID | ใช่ |
| Secret Access Key | S3 secret access key | ใช่ |
| Path-style access | Compatibility switch ค่าเริ่มต้น off บาง MinIO, OpenList หรือ self-hosted S3 service อาจต้องใช้ | ไม่ |
| Quota limit | ควบคุมว่าช่องทาง S3 นี้จะเข้าร่วมการเลือกช่องทางอัปโหลดตาม capacity หรือไม่ | ไม่ |
| Capacity limit | จำเป็นหลังเปิด quota limit เช่น 10 GB | จำเป็นเมื่อเปิด quota limit |
| Threshold | หยุดเขียนเมื่อ usage ถึง percentage นี้ เช่น 90% | จำเป็นเมื่อเปิด quota limit |
| Remark | หมายเหตุสำหรับดูแลเอง | ไม่ |
สร้าง Cloudflare R2 S3 API Keys
- เปิด Cloudflare Dashboard
- ไปที่
R2 Object Storage - หา
Manage R2 API Tokensหรือ entry สำหรับจัดการ API token

- สร้าง R2 API token ที่เข้าถึง target bucket ได้

- คัดลอก
Access Key IDและSecret Access Keyที่สร้างขึ้น

- กลับไปหน้า R2 bucket และยืนยัน bucket name
- จด S3 API endpoint ของ account โดยปกติหน้าตาแบบนี้:
text
https://your-account-id.r2.cloudflarestorage.comขั้นตอนตั้งค่า
- เปิด Upload Settings
- คลิกเพิ่มช่องทาง
- เลือก
S3 - ใส่ channel name ที่จำได้ เช่น
s3test - ใส่ S3 API endpoint ใน
Endpoint - ถ้าใช้ custom CDN ให้ใส่ใน
Custom CDN domain; ถ้าไม่ใช้ให้เว้นว่าง - ใส่ bucket name
- ใส่ region สำหรับตัวอย่าง Cloudflare R2 ใช้
auto - ใส่ Access Key ID และ Secret Access Key
- ปล่อย path-style access เป็น off เว้นแต่ provider ระบุชัดว่าต้องใช้
- ถ้าต้องการ capacity control ให้เปิด quota limit แล้วใส่ capacity limit และ threshold
- คลิก Save

วิธีตรวจสอบ
| รายการตรวจสอบ | วิธีตรวจสอบ |
|---|---|
| เห็นการ์ดช่องทาง | หลังบันทึก หน้า Upload Settings ควรแสดงการ์ดช่องทาง S3 |
| ช่องทางเปิดใช้งานอยู่ | สวิตช์มุมขวาบนของการ์ดควรอยู่ on |
| บันทึกฟิลด์สำคัญแล้ว | Detail view ควรแสดง Endpoint, Bucket, Region, path-style access และฟิลด์ที่เกี่ยวข้อง |
| การอัปโหลดใช้งานได้ | อัปโหลดรูปทดสอบแล้วตรวจว่า object ไปอยู่ใน target bucket |
| เปิดลิงก์ได้ | ลิงก์รูปภาพที่ได้หลังอัปโหลดควรเปิดได้ตามปกติ |
| การแสดง capacity ใช้งานได้ | ถ้าเปิด quota limit การ์ดควรแสดง capacity ที่ใช้แล้วและ limit ที่กำหนดค่าไว้ |
S3 capacity statistics คำนวณจาก local file records ของ ImgHost ไม่ได้ query provider bucket แบบ real time หลังบันทึก S3 configuration แล้ว ระบบจะคำนวณ quota ledger ใหม่จาก D1 records ปัจจุบัน

FAQ
ควรเปิด path-style access ไหม?
โดยทั่วไปไม่ต้อง
เปิดเฉพาะเมื่อ S3-compatible provider ไม่รองรับ virtual-hosted-style URLs หรือ provider documentation ระบุชัดว่าต้องใช้ path-style access บาง MinIO, self-hosted S3 และ OpenList-compatible endpoints อาจต้องใช้
CDN domain ใช้ทำอะไร?
ถ้าคุณวาง CDN หรือ custom access domain ไว้หน้า bucket ให้ใส่ตรงนี้
หลัง configure แล้ว file links ที่สร้างขึ้นจะเลือกใช้ domain นี้ก่อน ถ้าไม่ได้ใช้ CDN ให้เว้นว่าง
ทำไมการอัปโหลดจึงล้มเหลว?
ตรวจสิ่งเหล่านี้ก่อน:
- Endpoint เป็น URL
https://แบบเต็ม - Bucket name ถูกต้อง
- Region ตรงกับข้อกำหนดของ provider
- คัดลอก Access Key ID และ Secret Access Key มาครบ
- Key มี write permission สำหรับ target bucket
- Provider ไม่ต้องใช้ path-style access หรือถ้าต้องใช้ก็เปิดไว้แล้ว
รายการตรวจสอบด่วน
text
Prepare S3 Endpoint, Bucket, Region, Access Key, and Secret Key
-> Open Upload Settings
-> Add Channel
-> Select S3
-> Enter Endpoint / Bucket / Region / Access Key / Secret Key
-> Enter a CDN domain if needed
-> Leave path-style access off by default
-> Enable quota limit if needed
-> Save
-> Upload a test image and check the result