I'm trying to figure out how to retrieve the file size of a file uploaded to Google Drive. According to the docs this should be in the file metadata... but when I request it, file size is not in the metadata at all.
我正在尝试弄清楚如何检索上传到Google云端硬盘的文件的文件大小。根据文档,这应该在文件元数据中...但是当我请求它时,文件大小根本不在元数据中。
file = self.drive_service.files().get(fileId=file_id).execute()
print(file)
>>> {u'mimeType': u'application/x-zip', u'kind': u'drive#file', u'id': u'0B3JGbAfem1CrWnhtWq5qYlkzSXf', u'name': u'myfile.ipa'}
What am I missing here? How can I check the file size?
我在这里想念的是什么?如何查看文件大小?
2 个解决方案
#1
5
Per default, only a few select attributes are included in the metadata.
默认情况下,元数据中只包含少数选择属性。
To request specific attributes, use the fields
parameter:
要请求特定属性,请使用fields参数:
file = self.drive_service.files().get(fileId=file_id, fields='size,modifiedTime').execute()
This would query a file's size and modification time.
这将查询文件的大小和修改时间。
By the way, the link you posted refers to the old v2 API. You can find a list of all file attributes in the current v3 API here.
顺便说一下,您发布的链接是指旧的v2 API。您可以在此处找到当前v3 API中所有文件属性的列表。
#2
2
You are missing the 'fields' special query parameter here. It is used for giving partial response for google apis. The partial response is used mainly to improve api call performance.
您在这里缺少'fields'特殊查询参数。它用于为谷歌apis提供部分响应。部分响应主要用于改善api呼叫性能。
There is a slight change in the newly introduced v3 apis, the file list apis response give some default attributes in the response, unlike the v2 apis, which give all the attributes in response by default.
新引入的v3 apis略有变化,文件列表apis响应在响应中提供了一些默认属性,与v2 apis不同,后者默认提供响应中的所有属性。
Although, if you want all the attributes in the response, pass ' fields=* ' as query.
虽然,如果您想要响应中的所有属性,请将'fields = *'作为查询传递。
Hope, this helps!
希望这可以帮助!
#1
5
Per default, only a few select attributes are included in the metadata.
默认情况下,元数据中只包含少数选择属性。
To request specific attributes, use the fields
parameter:
要请求特定属性,请使用fields参数:
file = self.drive_service.files().get(fileId=file_id, fields='size,modifiedTime').execute()
This would query a file's size and modification time.
这将查询文件的大小和修改时间。
By the way, the link you posted refers to the old v2 API. You can find a list of all file attributes in the current v3 API here.
顺便说一下,您发布的链接是指旧的v2 API。您可以在此处找到当前v3 API中所有文件属性的列表。
#2
2
You are missing the 'fields' special query parameter here. It is used for giving partial response for google apis. The partial response is used mainly to improve api call performance.
您在这里缺少'fields'特殊查询参数。它用于为谷歌apis提供部分响应。部分响应主要用于改善api呼叫性能。
There is a slight change in the newly introduced v3 apis, the file list apis response give some default attributes in the response, unlike the v2 apis, which give all the attributes in response by default.
新引入的v3 apis略有变化,文件列表apis响应在响应中提供了一些默认属性,与v2 apis不同,后者默认提供响应中的所有属性。
Although, if you want all the attributes in the response, pass ' fields=* ' as query.
虽然,如果您想要响应中的所有属性,请将'fields = *'作为查询传递。
Hope, this helps!
希望这可以帮助!