LoginSignup
0
0

pythonでのgcsアップロードの注意点

Posted at

gsutilでcpコマンドによるアップロードは下記の様に、
ローカルのファイルを指定して、格納するフォルダを指定できます。

gsutil cp ***.txt gs://XXX/YYY

しかしpythonコードで行う場合は、GCS側のファイルパスにファイル名を含む必要があるので注意。

project_id  = "{ProjectName}"
bucket_name = "{BucketName}"
gcs_path    = "{GCSFilePath}"
local_path  = "{LocalFilePath}"

client = gcs.Client(project_id)
bucket = client.get_bucket(bucket_name)
# 格納するGCSのPathをファイル名込みで指定(/xxx/yyy.csv)
blob_gcs = bucket.blob(gcs_path)
# ローカルのファイルパスをファイル名こみで指定
blob_gcs.upload_from_filename(local_path)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0