'File not fond exception while uploading to drive
I have checked the past questions and they do not help in this situation. 1
FileNotFoundException when CREATING a google drive file
In my case, I am trying to upload a file that I received in a curl request to drive.
public static void uploadFile(Drive driveService, java.io.File fileToUpload, String name){
File fileMetadata = new File();
if(StringUtils.isEmpty(name)){
name = "Test";
}
fileMetadata.setName(name);
fileMetadata.setMimeType(SHEETS_MIME_TYPE);
FileContent mediaContent = new FileContent(XLSX_FILE_APPLICATION_TYPE, fileToUpload);
File file = null;
try {
file = driveService.files().create(fileMetadata, mediaContent)
.setFields(ID_FIELD)
.execute();
} catch (IOException e) {
e.printStackTrace();
}
log.info("File ID: {} " , file.getId());
}
As you can see, fileToUpload field passes the file that was received as part of the curl request. However, whenever I try to upload it, I get this error java.io.FileNotFoundException: files (No such file or directory)
Thanks
EDIT -
The code for generating the file object fileToUpload:
@RequestMapping(value = "/file", method = RequestMethod.POST, consumes = "multipart/form-data")
public String uploadFileToDrive(@RequestParam("files") MultipartFile multipartFile) throws Exception {
if(Objects.isNull(multipartFile)){
throw new IllegalArgumentException("No file present");
}
File file = new File(multipartFile.getName());
multipartFile.transferTo(file);
GoogleDriveClientService.uploadFile(driveService, file, "spring1");
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
