Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update docs and samples for drive export #1765

Merged
merged 1 commit into from
Jul 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -472,7 +472,7 @@ const res = await drive.files.export({
mimeType: 'application/pdf'
}, {
// Make sure we get the binary data
encoding: null
responseType: 'stream'
});
```

Expand Down
21 changes: 11 additions & 10 deletions samples/drive/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 => {
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test/samples/test.samples.drive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down