0

I'm trying to download a file from Google Docs via Axios and I get this error in return:

{
    "message": "Request failed with status code 404",
    "name": "AxiosError",
    "stack": "AxiosError: Request failed with status code 404\n    at settle (/Users/janswist/Developer/pdf-generator/functions/node_modules/axios/dist/node/axios.cjs:1261:12)\n    at Unzip.handleStreamEnd (/Users/janswist/Developer/pdf-generator/functions/node_modules/axios/dist/node/axios.cjs:2439:11)\n    at Unzip.emit (node:events:402:35)\n    at endReadableNT (node:internal/streams/readable:1343:12)\n    at processTicksAndRejections (node:internal/process/task_queues:83:21)",
    "config": {
        "transitional": {
            "silentJSONParsing": true,
            "forcedJSONParsing": true,
            "clarifyTimeoutError": false
        },
        "transformRequest": [
            null
        ],
        "transformResponse": [
            null
        ],
        "timeout": 0,
        "xsrfCookieName": "XSRF-TOKEN",
        "xsrfHeaderName": "X-XSRF-TOKEN",
        "maxContentLength": -1,
        "maxBodyLength": -1,
        "env": {
            "Blob": null
        },
        "headers": {
            "Accept": "application/json, text/plain, */*",
            "User-Agent": "axios/1.0.0",
            "Accept-Encoding": "gzip, deflate, br"
        },
        "method": "get",
        "url": "https://docs.google.com/document/d/15lhnj6sp1QFb9k-GmRCe8RVbwfbNM3es-xCt9mIu5Qc/export?format=docx",
        "responseType": "arraybuffer"
    },
    "code": "ERR_BAD_REQUEST",
    "status": 404
}

File exists and is shared, when you use the link directly it begins the download so I'm not sure how to even tackle it.

edit: My Axios code - pretty simple:

const { data } = await axios({
    method: 'get',
    url,
    responseType: 'arraybuffer'
  })
jean d'arme
  • 4,033
  • 6
  • 35
  • 70
  • By any chance have you seen this SO post on [How to download files using axios](https://stackoverflow.com/questions/41938718/how-to-download-files-using-axios)? – George May 25 '23 at 22:53
  • Can you provide your current script? And, what does `shared` of `File exists and is shared` mean? Is it publicly shared? Or, is it shared with your account without publicly sharing? – Tanaike May 25 '23 at 23:42
  • @George I haven't - thank you, will read it – jean d'arme May 26 '23 at 06:16
  • @Tanaike by `shared` I mean it's publicly available so there shouldn't be any issue with downloading it. My script works fine with static files like .docx files – jean d'arme May 26 '23 at 06:17

1 Answers1

1

Turns out I just had to update Axios library from version 1.0.0 to 1.4.0.

jean d'arme
  • 4,033
  • 6
  • 35
  • 70