8
votes

I use rest api "https://www.googleapis.com/drive/v3/files/fileId/export" "reference page" to get google Doc

I have document size ~ 5 MB when i try to get the file i had the json error :

{
  "error": {
    "errors": [
      {
        "domain": "global",
        "reason": "exportSizeLimitExceeded",
        "message": "This file is too large to be exported."
      }
    ],
    "code": 403,
    "message": "This file is too large to be exported."
  }
}

Is there any way to fix this error?

2
Hmm Google Docs does not have a file limit, therefore is your fileID correct and are you trying to export a Google Doc,Sheets or Slide?Conner
yes, for doc files < 5 MB it work but the problem in files > 5 MB.Abd

2 Answers

9
votes

Instead of using this export endpoint you can request exportLinks field in the Files: list:

curl \
  'https://www.googleapis.com/drive/v3/files/[FILE_ID]?fields=exportLinks' \
  --header 'Authorization: Bearer [ACCESS_TOKEN]' \
  --header 'Accept: application/json'

That will return something like this (these are links I got for a Google Slides presentation):

{
 "exportLinks": {
  "application/vnd.oasis.opendocument.presentation": "https://docs.google.com/feeds/download/presentations/Export?id=[FILE_ID]&exportFormat=odp",
  "application/pdf": "https://docs.google.com/feeds/download/presentations/Export?id=[FILE_ID]&exportFormat=pdf",
  "application/vnd.openxmlformats-officedocument.presentationml.presentation": "https://docs.google.com/feeds/download/presentations/Export?id=[FILE_ID]&exportFormat=pptx",
  "text/plain": "https://docs.google.com/feeds/download/presentations/Export?id=[FILE_ID]&exportFormat=txt"
 }
}

And those urls don't have such a hard size limit (I was able to get out ~50mb PDFs)

2
votes

As stated in the error message there is a limit to how big of a file the API can export. There is really nothing you can do to fix that your going to have to do it with smaller files.

{
"error": {
"errors": [
{
"domain": "global",
"reason": "exportSizeLimitExceeded",
"message": "This file is too large to be exported."
}
],
"code": 403,
"message": "This file is too large to be exported."
}
}