question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Don't know How to save .docx file from google drive

See original GitHub issue

I have tried many methods - node.js write Buffer, Streams etc.

    var xhr = new _XMLHttpRequest();
//children is response of `get` file
    xhr.open('GET', children.downloadUrl);
    xhr.setRequestHeader('Authorization', 'Bearer ' + _accessToken);
    xhr.onload = function() {
        fs.writeFile(children.title, xhr.responseText)
    });

Content of xhr.responseText is something like that ��▬h��↕E6M��~��3�3∟�9�� � �►��/2�:���♂�4��]�♀I�R���► $SB6Q���c↔��H�=;+ ���►q�3Tdכ��@!T��hEl_�|�I�↨��h(�^:▬�[h̓D♠��f���♠*���ݾ��M→ �1⌂♦"N�↑�o�]�7U$��A6����♠�W��k`�f▬♫��K�Z�^‼�0{<Z�▼�]F�����

                             ���J♥A♀��♣�a�}7�

"���H�w"�♥���☺w♫̤ھ�� �P�^����O֛���;�<♠�aYՠ؛`G�kxm��PY�[��g Gΰino�/<���<�1��ⳆA$>"f3��\�ȾT��∟I S�������W♥����Y

Please help me to know what is the format of the data I am getting from Drive Api and write it in which format so that I got a complete .docx file

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
davestevenscommented, Dec 7, 2015

Here is an example of how I am downloading files: https://gist.github.com/davestevens/6f376f220cc31b4a25cd

An example for just a single file:

var google = require("googleapis"),
    drive = google.drive("v2"),
    fs = require("fs");

// For configuring your Client
var config = {
  "client_id": "client_id",
  "client_secret": "client_secret",
  "scope": "scope",
  "redirect_url": "redirect_rul",
  "tokens": {
    "access_token": "access_token",
    "token_type": "Bearer",
    "id_token": "id_token",
    "refresh_token": "refresh_token",
    "expiry_date": "expiry_date"
  }
};

var client = new google.auth.OAuth2(
  config.client_id,
  config.client_secret,
  config.redirect_url
);
client.setCredentials(config.tokens);

var file = fs.createWriteStream("./downloadedFile"),
    fileId = "FILEID"; // The Id of the file you want to download
drive.files.get({ auth: client, fileId: fileId, alt: "media" }).pipe(file);
0reactions
robertrossmanncommented, Mar 27, 2015

Just posted an answer on SO. To summarise, XMLHttpRequest does not support binary downloads; you need to use something else that does.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to download a Docs files without converting it
You can download to other formats by opening the Docs document and going to File > Download. However, if you try to download...
Read more >
How to Save a Google Doc as a Word File - Daemen College
1- Open up the file you want to download in Google Docs. In this case, I opened a file called “docx”. 2- Next,...
Read more >
how to edit and save a word document in google docs drive
Assalamu Walaikum, in this video, I will show you, how to edit and save a word document in google docs drive. let's get...
Read more >
How to save a Google Doc as a PDF or Word document
Click Microsoft Word (. docx) to save your Google Doc as a Word document. Click PDF Document (. pdf) to save your Google...
Read more >
How to enable .docx creation in the Google Docs app
If you plan to share the file immediately, save it locally. If you plan to work with the document from the web-based version...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found