Reputation: 85
I am trying to get the Size of files with google drive API
const filesFilteredByDate = await axios.get('https://www.googleapis.com/drive/v3/files', {
q: `mimeType = 'application/vnd.google-apps.folder'`,
fields: 'files(id, name, size, modifiedTime)',
orderBy: 'modifiedTime desc',
spaces: 'drive',
headers: {
authorization: `Bearer ${accessToken}`
}
});
But it does not return the size and modified time of the folder
So how do i get size , modifiedTime and createdTime
Upvotes: 1
Views: 215
Reputation: 1224
Size of the folder is not provided by google drive api more id, name,kind,mimeType are the default data object
Moreover, put your fields inside params if you are using Axios just like that
const filesFilteredByDate = await axios.get('https://www.googleapis.com/drive/v3/files', {
params: {
q: "mimeType='application/vnd.google-apps.folder'",
fields: "files(id,name,createdTime,modifiedTime,parents)",
orderBy: "modifiedTime desc",
},
headers: {
authorization: `Bearer ${accessToken}`
}
});
Upvotes: 2
Reputation: 116948
Not all file types have a size. your searching for folders only folders dont return a size.
{
"id": "1R_QjyKy27C-3ASMJJa",
"name": "YouTube",
"mimeType": "application/vnd.google-apps.folder",
"modifiedTime": "2021-12-14T08:48:38.786Z"
},
If you try a diffrent file type you will find it does return a size fore example a zip file
{
"id": "107GrdcfBFVuWjlMZEKN7qAqsdvsH",
"name": "backup_2022-02-16-1013_Daimto_e3763aa68b2c-others.zip",
"modifiedTime": "2022-02-16T08:14:16.917Z",
"size": "17849423"
},
Upvotes: 1