Reputation: 329
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.
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?
Upvotes: 6
Views: 9090
Reputation: 31
Passing 'size'
within fields
should work.
Example: fields='size'
Although if the file is native to Google Drive such as a file made within Google Docs or Sheets those files do not take up space against your quota and thus don't have a size.
Upvotes: 0
Reputation: 119
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.
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.
Although, if you want all the attributes in the response, pass ' fields=* ' as query.
Hope, this helps!
Upvotes: 2
Reputation: 43146
Per default, only a few select attributes are included in the metadata.
To request specific attributes, use the fields
parameter:
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.
Upvotes: 13