[英]Get size of file using blob in google cloud
i use this code to get object of file in google cloud.我使用此代码在谷歌云中获取文件的 object。
client = storage.Client.from_service_account_json("./credential.json")
bucket = client.get_bucket(bucket)
object = bucket.blob(fileurlName)
and i have url of file in variable fileurlName, but the results size is none and chunk size is not the same as file size so how can i change it to give me the exact size of file in google cloud?我在变量fileurlName中有url文件,但结果大小没有,块大小与文件大小不同,所以我怎样才能改变它给我谷歌云中文件的确切大小?
It's quite tricky.这很棘手。
In fact, when you use the method of the type, you simply ask the client library to build a correct path to access to the object.其实在使用type的方法时,只要让客户端库建一个正确的路径就可以访问object。 But you don't access it, you only build a local reference to it.
但是你不能访问它,你只能建立一个对它的本地引用。 And thus all the value (or almost) are none.
因此所有的价值(或几乎)都没有。
If you want to GET the object, use the get_ method.如果要获取 object,请使用 get_ 方法。
In your case replace the bucket.blob(fileurlName)
by bucket.get_blob(fileurlName)
.在您的情况下,将
bucket.blob(fileurlName)
bucket.get_blob(fileurlName)
。 This time, the object metadata are really fetched (the API call is performed) and the size field is populated.这一次,真正获取了 object 元数据(执行了 API 调用)并填充了大小字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.