0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

pythonでのgoogle cloud storageへのアップロード時の注意点

Last updated at Posted at 2023-10-24

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?