背景
Pythonで、GCS のファイルサイズを普通に取得しようとするも None が返ってくる?
# prompt: Google Could Storage上のファイルのサイズを調べます。 # Import the google.cloud.storage library. from google.cloud import storage # Instantiate a client. storage_client = storage.Client() # Get the bucket that the file will be uploaded to. bucket = storage_client.bucket('your-bucket-name') # Get the file object. file = bucket.get_blob('file_name.txt') # Print the file's size. print(file.size)
None
解決策
get_blob
か、reload()
する
具体的には、
# prompt: Google Could Storage上のファイルのサイズを調べます。 # Import the google.cloud.storage library. from google.cloud import storage # Instantiate a client. storage_client = storage.Client() # Get the bucket that the file will be uploaded to. bucket = storage_client.get_bucket('your-bucket-name') # Get the file object. file = bucket.get_blob('file_name.txt') # Print the file's size. print(file.size)
# prompt: Google Could Storage上のファイルのサイズを調べます。 # Import the google.cloud.storage library. from google.cloud import storage # Instantiate a client. storage_client = storage.Client() # Get the bucket that the file will be uploaded to. bucket = storage_client.get_bucket('your-bucket-name') # Get the file object. file = bucket.blob('file_name.txt') file.reload() # Print the file's size. print(file.size)
まとめ
ただ、get_blob
するか、reload()
するだけ。