With the following code
client = storage.Client(project="prod-model-test",credentials=credentials)
bucket = client.get_bucket("my_bucket")
blob = bucket.blob("blob_name")
blob.upload_from_filename("test_file.txt")
I will upload the test_file.txt
to the google cloud storage/bucket called "my_bucket"
.
From the documentation , "blob_name"
is "the unique path of the object in the bucket".
How is that understood ie what difference would it do if I called it "blob_foo"
instead of "blob_name"
, since when I download it again, I just specify the name, test_file.txt
.
blob_name here is merly a parameter and it can be any string you want "blob_foo" or anything else and it's the name of your file when you upload it to the bucket. the meaning of the unique path of the object in the bucket
is that if you name a file "test1.txt" with blob name "testblob" and try to upload another file "test2.txt" with the same blob name, then the later will override the first. that's why it needs to be unique. notice that you can also create files in nest way like:
blob = bucket.blob("folder/test.txt")
this will create a folder in the bucket and add this file to it.
that's why it needs to be a unique path
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.