Я получаю исключение NullPointerException от uploadedFile.getName() в следующем коде, который использует google api. Если я изменил это на строку fileName, код будет работать нормально.Почему google drive api создает файл с нулевым именем
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);
Для конкретного вопроса, почему файл возвращается следующим утверждением имеет нуль для имени?
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>