Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Drive: The file size is null

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!

like image 276
aGO Avatar asked Oct 05 '12 13:10

aGO


People also ask

What does NULL mean Google Drive?

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.

Why are Google Docs 0 bytes?

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.

How do I see file size in Google Drive?

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.

Why is Google Drive not showing files?

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.


1 Answers

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.

like image 147
NameSpace Avatar answered Oct 16 '22 09:10

NameSpace