파이썬을 사용한 Firebase Storage 작업
배경.
Firestore를 사용하면 일주일에 한 번씩 대량의 데이터 액세스 위치를 만들면 Storage로 문제가 없는 것을 알아볼 수 있습니다.
결론
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
#from firebase_admin import storage
from google.cloud import storage
GOOGLE_APPLICATION_CREDENTIALS=os.environ["GOOGLE_APPLICATION_CREDENTIALS"]
FIREBASE_STORAGE_BUCKET=os.environ["FIREBASE_STORAGE_BUCKET"]
cred = credentials.Certificate(GOOGLE_APPLICATION_CREDENTIALS)
firebase_admin.initialize_app(cred,{'storageBucket':FIREBASE_STORAGE_BUCKET})
bucket = storage.bucket()
def upload_blob(source_file_name, destination_blob_name):
storage_client = storage.Client()
bucket = storage_client.bucket(FIREBASE_STORAGE_BUCKET)
blob = bucket.blob(destination_blob_name)
blob.upload_from_filename(source_file_name)
print(
"File {} uploaded to {}.".format(
source_file_name, destination_blob_name
)
)
def download_blob(source_blob_name, destination_file_name):
storage_client = storage.Client()
bucket = storage_client.bucket(FIREBASE_STORAGE_BUCKET)
blob = bucket.blob(source_blob_name)
blob.download_to_filename(destination_file_name)
print(
"Blob {} downloaded to {}.".format(
source_blob_name, destination_file_name
)
)
def blob_list(prefix=""):
storage_client = storage.Client()
bucket = storage_client.bucket(FIREBASE_STORAGE_BUCKET)
blobs = list(bucket.list_blobs(prefix=prefix))
print(
"Blob list to {}.".format(
blobs
)
)
return blobs
blob_list
에서 prefix
를 지정하면 특정 폴더 아래의 파일만 추출할 수 있습니다.아래 내용을 참고하시오.
참조: https://googleapis.dev/python/storage/latest/client.html
사용법
환경 변수
FIREBASE_STORAGE_BUCKET
에 통 이름을 설정하고GOOGLE_APPLICATION_CREDENTIALS
에 Firebase에서 다운로드한 인증 파일을 설정하십시오.통 이름
Firebase store 위쪽에 있는 문자열입니다.
이 경우 제거
gs://
분Video-xxxx.appspot.com
이다.Key 파일
1.
プロジェクトの概要
측면에서 선택하십시오プロジェクトを設定
.2. 위 탭에서 서비스 계정을 선택
3. 아래
新しい秘密鍵の生成
를 누르면 JSON 파일을 다운로드할 수 있습니다.Reference
이 문제에 관하여(파이썬을 사용한 Firebase Storage 작업), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://zenn.dev/hashito/articles/377330864bcd57텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)