当我尝试在Google Drive上通过getFileSize()获取文件大小时,结果为空。我知道当文件没有存储在驱动器上,但文件存储在驱动器上时,结果可能是null (downloadUrl不同于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);
}
你能帮帮我吗?
谢谢!aGO!
发布于 2013-05-30 01:36:16
在HttpResponse类上调用getHeaders().GetContentLength()
(代码假设myurl
是您的url):
HttpResponse resp = service.getRequestFactory().buildGetRequest(new GenericUrl(myurl)).execute();
Log.v("abc","file size is : " + resp.getHeaders().getContentLength());
发布于 2014-11-12 18:14:22
来自Google Drive的默认文件列表请求将包括文件大小,但仅适用于文件大小不隐含为空的文件。例如,文件夹和Google电子表格(简单的链接)将为空。
这可以通过Drive API exlporer进行验证。只需在字段编辑器中请求filesize和mimtype即可。键-值对将不会包括在所提到的文件类型的响应中,即使请求了文件大小--但对于其他类型将被返回。
发布于 2012-10-06 07:49:03
请尝试使用OAuth 2.0游乐场重现此问题:
https://developers.google.com/oauthplayground
通过使用,我们可以发送原始请求并检查OAuth中是否存在问题。我试着自己复制它,它工作正常。
https://stackoverflow.com/questions/12747239
复制相似问题