when I try to get the file size by getFileSize() on Google Drive the result is null. I know that the result can be null when the file in not stored on Drive but the file is stored on Drive (downloadUrl is different from null).
Drive lService = new Builder(new NetHttpTransport(), new JacksonFactory(), lCredential).setApplicationName("TODO").build();
FileList files = lService.files().list().execute();
List<FileDTO> lResult = new ArrayList<FileDTO>();
for (File lFile : files.getItems()) {
DriveFileDTO lFileDTO = new DriveFileDTO();
lFileDTO.setName(lFile.getTitle());
lFileDTO.setMimeType(lFile.getMimeType());
lFileDTO.setSize(lFile.getFileSize()); // <-- FileSize = NULL
lFileDTO.setUrl(lFile.getDownloadUrl());
lResult.add(lFileDTO);
}
Can you help me?
Thanks! aGO!
A default request for a file list from Google Drive will include file size, but only for files where the file size is not implicitly null. For example, folders and Google spreadsheets (which are simply links) will be null. This can be verified with the Drive API exlporer.
Native Google files (Docs, Spreadsheets, Slides and Forms) do not count against a user's storage quota and thus show as zero bytes via the API. Google does not expose actual storage usage of these native files but you can get an approximation by exporting the file and checking the download size.
To bring up your list of files in size order, go to Google Drive and on the bottom left hand side you will see 'GB used'. Hover over this and in the pop up click Drive. Or to speed things up click this URL: https://drive.google.com/drive/quota.
You can delete the cache related to Google Drive and check if that helps. To do that, select the padlock-shaped View site information icon on the address bar and select Site Settings. Follow by selecting Clear data. Then, reload Google Drive and check if the missing files show up.
A default request for a file list from Google Drive will include file size, but only for files where the file size is not implicitly null. For example, folders and Google spreadsheets (which are simply links) will be null.
This can be verified with the Drive API exlporer. Simply request filesize and mimtype in the fields editor. A key-value pair will not be included in the response for the file types mentioned, even though a filesize was requested -- yet will be returned for other types.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With