Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export google drive documents to supported MIME types

I am uploading files to Drive using rest api(Version 3), I am able to upload those. But when I try to export that file then I am getting

403:Export only supports Google Docs.

If I create file on drive editor and then export that, it gets exported properly. In Version 2 of API I could see there was an option

convert=true

But in Version 3 there is no such option.

Stack over Flow link But this is for Version 2

like image 501
atti Avatar asked Nov 08 '22 16:11

atti


1 Answers

When uploading files, you just have to specify the Google docs mimeType for them to be a Drive file.

The documentation gave an example of converting a .csv file in to a Sheets file.

File fileMetadata = new File();
fileMetadata.setName("My Report");
fileMetadata.setMimeType("application/vnd.google-apps.spreadsheet");

java.io.File filePath = new java.io.File("files/report.csv");
FileContent mediaContent = new FileContent("text/csv", filePath);
File file = driveService.files().create(fileMetadata, mediaContent)
.setFields("id")
.execute();
System.out.println("File ID: " + file.getId());
like image 58
abielita Avatar answered Jan 04 '23 03:01

abielita