Use APIs to Work with Cloud Storage

목록
- Cloud Storage: Qwik Start - CLI/SDK ⬅️ 오늘의 Lab!
- APIs Explorer: Cloud Storage
- Introduction to APIs in Google Cloud
- Use APIs to Work with Cloud Storage: Challenge Lab
Google Cloud 명령줄을 사용하여 스토리지 버킷을 만들고, 여기에 객체를 업로드하고, 폴더 및 하위 폴더를 만들고, 객체에 공개적으로 액세스할 수 있도록 설정하는 방법을 알아보자.

# Region 수정 필요
gcloud config set compute/region "REGION"

# unique한 버킷 이름으로 수정 필요
gcloud storage buckets create gs://<YOUR-BUCKET-NAME>

curl https://upload.wikimedia.org/wikipedia/commons/thumb/a/a4/Ada_Lovelace_portrait.jpg/800px-Ada_Lovelace_portrait.jpg --output ada.jpg

# 생성한 버킷 이름으로 변경 필요
gcloud storage cp ada.jpg gs://YOUR-BUCKET-NAME

rm ada.jpg

# 버킷 이름 변경 필요
gcloud storage cp -r gs://YOUR-BUCKET-NAME/ada.jpg .

# 버킷 이름 변경 필요
gcloud storage cp gs://YOUR-BUCKET-NAME/ada.jpg gs://YOUR-BUCKET-NAME/image-folder/
➡️ image-folder 폴더 생성 후, 이미지를 폴더 안에 복사

# 버킷 이름 수정 필요
gcloud storage ls gs://YOUR-BUCKET-NAME

# 버킷 이름 수정 필요
gcloud storage ls -l gs://YOUR-BUCKET-NAME/ada.jpg

# 버킷 이름 수정 필요
gcloud storage objects update gs://YOUR-BUCKET-NAME/ada.jpg --add-acl-grant=entity=allUsers,role=READER

# 버킷 이름 수정 필요
gcloud storage objects update gs://YOUR-BUCKET-NAME/ada.jpg --remove-acl-grant=allUsers

# 버킷 이름 수정 필요
gcloud storage rm gs://YOUR-BUCKET-NAME/ada.jpg
➡️ 버킷의 이미지 파일인 객체를 삭제
➡️ 새로고침하면 이미지 파일의 복사본이 Cloud Storage에 저장되어 있지 않지만, image-folder/ 폴더에 만든 사본은 계속 남아 있다.