GCS

Google Cloud Storage

Cloud Storage에 올려두고 로컬에 파일이 없을 경우 다운로드.

import os
from google.cloud import storage

BUCKET = "bucket"
PATH = '/ml-experiments'
FILE = 'sample.csv'

client = storage.Client()
if not os.path.exists(PATH + '/' + FILE):
    bucket = client.get_bucket(BUCKET)
    blob = bucket.blob(FILE)
    blob.download_to_filename(PATH + '/' + blob.name)

    print('Downloaded to {}'.format(PATH + '/' + blob.name))

업로드 과정도 동일. blob에 gcs 파일명, upload에 로컬 파일명

client = storage.Client()
bucket = client.get_bucket(BUCKET)
blob = bucket.blob('X.pkl')
blob.upload_from_filename(os.getcwd() + '/X.pkl')

Last Modified: 2021/12/18 01:13:51

is a collection of Papers I have written.
© 2000 - Sang-Kil Park Except where otherwise noted, content on this site is licensed under a CC BY 4.0.
This site design was brought from Distill.