Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google drive export non-google doc file

I am trying to export several files from Google drive using this code:

String str = "application/rft";
OutputStream outputStream = new ByteArrayOutputStream();
driveService.files().export(fileId, str).executeAndDownloadTo(outputStream);

and it works properly but, when I try to export an application/pdf or application/png or application/jpeg file I am getting this error:

403 Forbidden
{
  "code" : 403,
  "errors" : [ {
    "domain" : "global",
    "message" : "Export only supports Google Docs.",
    "reason" : "fileNotExportable"
  } ],
  "message" : "Export only supports Google Docs."
}

I would like to know if there is a way to get this file's content using Java

Thanks in advance

like image 271
Aldeguer Avatar asked Sep 19 '17 14:09

Aldeguer


1 Answers

Google Docs can download using files.export. But when it downloads files (pdf, png and jpeg) except for Google Docs, please use files().get().

You can see the detail information at here. Also you can see the sample script.

Edit :

This is a sample script for downloading files except for Google Docs.

String fileId = "### file ID ###";
OutputStream out = new FileOutputStream("### output filename ###");
driveService.files().get(fileId).executeMediaAndDownloadTo(out);
like image 166
Tanaike Avatar answered Sep 29 '22 09:09

Tanaike