
เปิด Google storage ให้ทุกคนเข้าถึงไฟล์ได้
ปกติหากเราสร้าง Google storage ขึ้นมาไฟล์ใน storage ทั้งหมดนั้นจะเป็นแบบ Private ไม่มีใครสามารถเข้ามาอ่านไฟล์ได้โดยตรง นอกจากเราจะทำการ Signed URLs ให้ถึงจะเข้าถึงไฟล์ได้
แต่เราสามารถทำการเปิดสิทธิ์การเข้าถึงให้สามารถใครก็ได้เข้าถึงไฟล์เราได้เลยผ่าน url ของ Storage ตรงๆ เช่น https://storage.googleapis.com/bucket-name/folder/file.jpeg
สามารถทำได้ ดังนี้
วิธีการทำ Google storage ทุกคนเข้าถึงไฟล์ได้
ให้ไปที่ Google storage แล้วติ้กช่องข้างหน้า Bucket ที่ต้องการ จากนั้นกด Show info panel ขวามือ จากนั้นกด Add principal

ในช่อง New principals ให้พิมพ์ AllUsers
และเลือก Role เป็น Storage Object Viewer
แล้วกด Save

จากนั้นเขาจะเตือนว่า เรากำลังจะเปิดให้ bucket นี้มันเป็นแบบ Public นะจะเอาไหม เราก็กด Allow public access ไป

พอเรากลับมาดูที่ bucket เราจะเจอกับคำว่า Public to internet นั้นแสดงว่า bucket ของเรานั้นเปิดให้ทุกคนเข้ามาดูไฟล์ข้างในได้ละ

การเปิด public bucket นั้นอยู่เรื่องความปลอดภัยผมจะไม่ค่อยแนะนำให้ทำเท่าไร ถ้าไฟล์ในนี้มันไม่ค่อยสำคัญเท่าไร แล้วเราอยากได้ความสะดวกในการเข้าถึงไฟล์ก็เปิด public ได้...