From 5df21d779d6e547321135b5afff80b365449667f Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Fri, 19 Jul 2019 13:50:11 -0700 Subject: [PATCH] docs: update docs and samples for drive export --- README.md | 4 ++-- samples/drive/export.js | 21 +++++++++++---------- test/samples/test.samples.drive.ts | 4 ++-- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 4162554882..2fc8b4d184 100644 --- a/README.md +++ b/README.md @@ -462,7 +462,7 @@ async function main() { main().catch(console.error); ``` -You can also override *gaxios* options per request, such as `url`, `method`, and `encoding`. +You can also override *gaxios* options per request, such as `url`, `method`, and `responseType`. For example: @@ -472,7 +472,7 @@ const res = await drive.files.export({ mimeType: 'application/pdf' }, { // Make sure we get the binary data - encoding: null + responseType: 'stream' }); ``` diff --git a/samples/drive/export.js b/samples/drive/export.js index e4fddf615d..99606d5149 100644 --- a/samples/drive/export.js +++ b/samples/drive/export.js @@ -17,6 +17,7 @@ const {google} = require('googleapis'); const sampleClient = require('../sampleclient'); const fs = require('fs'); const os = require('os'); +const path = require('path'); const drive = google.drive({ version: 'v3', @@ -25,17 +26,17 @@ const drive = google.drive({ async function runSample() { // [START main_body] - return new Promise(async (resolve, reject) => { - const fileId = '1ZdR3L3qP4Bkq8noWLJHSr_iBau0DNT4Kli4SxNc2YEo'; - const dest = fs.createWriteStream(`${os.tmpdir()}/resume.pdf`); - - const res = await drive.files.export( - {fileId, mimeType: 'application/pdf'}, - {responseType: 'stream'} - ); + const fileId = '1EkgdLY3T-_9hWml0VssdDWQZLEc8qqpMB77Nvsx6khA'; + const destPath = path.join(os.tmpdir(), 'important.pdf'); + const dest = fs.createWriteStream(destPath); + const res = await drive.files.export( + {fileId, mimeType: 'application/pdf'}, + {responseType: 'stream'} + ); + await new Promise((resolve, reject) => { res.data .on('end', () => { - console.log('Done downloading document.'); + console.log(`Done downloading document: ${destPath}.`); resolve(); }) .on('error', err => { @@ -49,7 +50,7 @@ async function runSample() { // if invoked directly (not tests), authenticate and run the samples if (module === require.main) { - const scopes = ['https://www.googleapis.com/auth/drive.metadata.readonly']; + const scopes = ['https://www.googleapis.com/auth/drive.readonly']; sampleClient .authenticate(scopes) .then(runSample) diff --git a/test/samples/test.samples.drive.ts b/test/samples/test.samples.drive.ts index 6ca88293ec..0656d5b25c 100644 --- a/test/samples/test.samples.drive.ts +++ b/test/samples/test.samples.drive.ts @@ -53,12 +53,12 @@ describe('Drive samples', () => { }); it('should download the doc', async () => { - const fileId = '1ZdR3L3qP4Bkq8noWLJHSr_iBau0DNT4Kli4SxNc2YEo'; + const fileId = '1EkgdLY3T-_9hWml0VssdDWQZLEc8qqpMB77Nvsx6khA'; const scope = nock(Utils.baseUrl) .get(`/drive/v3/files/${fileId}/export?mimeType=application%2Fpdf`) .replyWithFile(200, someFile); await samples.export.runSample(); - assert(fs.existsSync(`${os.tmpdir()}/resume.pdf`)); + assert(fs.existsSync(`${os.tmpdir()}/important.pdf`)); scope.done(); });