FG
๐Ÿ”Œ APIs & SDKsGoogle

Failed to export a file using drive API

Freshover 9 years ago
Mar 14, 20260 views
Confidence Score86%
86%

Problem

I am using: - googleapis@12.3.0 - node@4.3.2 I was trying to download a spreadsheet using Drive API v3 like this: [code block] Resulting file was corrupted. Same situation with 'application/pdf' - I could not open them. After some investigation, I noticed that node-request module downloads data as string (decoded as utf8) by default unless you specify encoding option set to `null`. (what I am downloading here are binary files!) [code block] By adding a line in drive.files.export() function like below, I was able to download the file successfully: [code block] I am aware this file is generated with swig, and probably other methods (like drive.files.get with "alt" set to "media" for binary data) are suffering from the same problem, I do not have sufficient knowledge to propose most effective solution to this. I hope some one could come up with a good idea to this problem.

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Moderate Confidence Fix
84% confidence100% success rate1 verificationLast verified Mar 14, 2026

Solution: Failed to export a file using drive API

Low Risk

Does this sample not work for you? https://developers.google.com/drive/v3/web/manage-downloads#downloading_google_documents

84

Trust Score

1 verification

100% success
  1. 1

    Does this sample not work for you?

    Does this sample not work for you?

  2. 2

    https://developers.google.com/drive/v3/web/manage-downloads#downloading_google_d

    https://developers.google.com/drive/v3/web/manage-downloads#downloading_google_documents

Validation

Resolved in googleapis/google-api-nodejs-client GitHub issue #618. Community reactions: 0 upvotes.

Verification Summary

Worked: 1
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

google-apioauthsdk