简体   繁体   English

使用谷歌云中的blob获取文件大小

[英]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.

相关问题 如何获取Cloud Storage对象的Blob大小? - How to get the blob size of Cloud Storage object? 如何从谷歌云 python 库中获取对象的文件大小? - How to get file size of objects from google cloud python library? 验证文件路径的 Google Cloud Storage bucket.get_blob 返回 None - Google Cloud Storage bucket.get_blob to verified file path returns None Flask:如何使用 upload_blob 将用户文件上传到 Google Cloud Storage - Flask: How to upload a user file into Google Cloud Storage using upload_blob Google Cloud Storage - Python 客户端 - 获取 Blob 的链接 URL - Google Cloud Storage - Python Client - Get Link URL of a blob Google Cloud Storage:Python API 使用通配符获取 blob 信息 - Google Cloud Storage : Python API get blob information with wildcard Google Cloud Storage 列出具有特定文件名的 Blob 对象 - Google Cloud Storage List Blob objects with specific file name 获取 Google Cloud PubSub 中单条消息的大小 - Get the size of a single message in Google Cloud PubSub Google App Engine Blob存储…更改文件大小的语法? - Google App Engine Blob Store… Syntax for changing file size? 使用 Azure-Storage-Blob Python 读取 Blob 容器目录中每个 Blob 的文件大小 - Reading the File size for each blob inside a directory of a Blob Container using Azure-Storage-Blob Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM