We are using Google Drive V2 client library to fetch the file size of a document. For few documents we are getting filesize as null even if the file has content in it.
Drive service = new Drive.Builder(httpTransport, jsonFactory, httpRequestInitializer).build();
com.google.api.services.drive.model.File file = service.files().get(fileId).execute();
Long fileSize=file.getFileSize();
We are facing this issue mostly for .docx file opened with Google Docs. These are few files for which we are facing the issue. We are not able to find the file size for these files in Drive UI also
Can someone assist with this?
This behavior is expected based on official documentation.
Important: As of 1 June 2021, newly created Google Docs, Sheets, Slides, Drawings, Forms or Jamboard files count towards storage. Files that already exist don't count towards storage unless they're modified on or after 1 June 2021.
So based on the affected files in your screenshot, I see that those files were created before June 2021 (Google Docs, Sheets, Slides, Drawings, Forms, or Jamboard files created before that date did not count toward your Drive storage) and most likely those files have not been modified after that date so that's why those files does not show size as they not count towards your Drive storage.
Reference: