Google Drive:文件大小为空 [英] Google Drive: The file size is null

查看:21
本文介绍了Google Drive:文件大小为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试通过 Google Drive 上的 getFileSize() 获取文件大小时,结果为空.我知道当文件未存储在云端硬盘上但文件存储在云端硬盘上时结果可能为空(downloadUrl 与空值不同).

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);
    }

你能帮帮我吗?

谢谢!去吧!

推荐答案

在 HttpResponse 类上调用 getHeaders().GetContentLength() (代码假定 myurl 是你的 url):

Call getHeaders().GetContentLength() on the HttpResponse Class (code assumes myurl is your url):

HttpResponse resp = service.getRequestFactory().buildGetRequest(new GenericUrl(myurl)).execute();
Log.v("abc","file size is : " + resp.getHeaders().getContentLength());

这篇关于Google Drive:文件大小为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆