Google drive api 为什么GoogleDriveAPI创建了一个空名称的文件

Google drive api 为什么GoogleDriveAPI创建了一个空名称的文件,google-drive-api,Google Drive Api,在下面利用google api的代码中,我从uploadedFile.getName()中得到了一个NullPointerException。如果我将其更改为字符串文件名,代码就可以正常工作 public static void downloadFile(boolean useDirectDownload, File uploadedFile, java.io.File parentDir)throws IOException { OutputStream out = new FileO

在下面利用google api的代码中,我从uploadedFile.getName()中得到了一个NullPointerException。如果我将其更改为字符串文件名,代码就可以正常工作

public static void downloadFile(boolean useDirectDownload, File uploadedFile, java.io.File parentDir)throws IOException {
    OutputStream out = new FileOutputStream(new java.io.File(parentDir, uploadedFile.getName()));
    DRIVE.files().get(uploadedFile.getId()).executeMediaAndDownloadTo(out);
}
我理解空指针是什么,但不确定为什么在这种情况下我会得到一个空指针,因为在调用下载文件之前,我在前面的代码中设置了文件名,文件以我设置的名称上载

public static File uploadFile(boolean useDirectUpload, String uploadFilePath, String fileType, String fileName) throws IOException {

File fileMetadata = new File();
fileMetadata.setName(fileName);
fileMetadata.setMimeType(fileType);

java.io.File filePath = new java.io.File(uploadFilePath);
FileContent mediaContent = new FileContent(fileType, filePath);
return DRIVE.files().create(fileMetadata, mediaContent)
        .setFields("id")
        .execute();
}
上述两组代码由

java.io.File parentDir = P.createDirectory("C:\\DIR");         
File uploadedFile = P.uploadFile(true, "C:\\DIR\AA.pdf", "application/pdf", "BB.pdf");
P.downloadFile(true, uploadedFile, parentDir);
对于一个特定的问题,为什么下面语句返回的文件的名称为null?

return DRIVE.files().create(fileMetadata, mediaContent)
            .setFields("id")
            .execute();
驱动器服务的Maven依赖项:

<dependency>
    <groupId>com.google.apis</groupId>
    <artifactId>google-api-services-drive</artifactId>
    <version>v3-rev40-1.22.0</version>
</dependency>

com.google.api
谷歌api服务驱动
v3-rev40-1.22.0

为什么以下语句返回的文件的名称为null?


因为您尚未请求在REST响应中包含文件名。将
.setFields(“id”)
更改为
.setFields(“id,name”)
为什么以下语句返回的文件名称为null?


因为您尚未请求在REST响应中包含文件名。将
.setFields(“id”)
更改为
.setFields(“id,name”)
当调用
create
方法时,您只能获得
id
作为部分响应的一部分,因为它是
setFields
-中指定的唯一方法


尝试添加其他字段(
name
,以及其他必要的相关字段),调用应该可以

当调用
create
方法时,您只会得到
id
作为部分响应的一部分,因为它是
setFields
中唯一指定的方法

尝试添加其他字段(
name
,以及其他必要的相关字段),调用应该可以正常工作