The ID of the file in Google Drive you'd like to download
You can save the file anywhere to the /tmp
directory in your workflow, e.g. /tmp/file.pdf
.
async
(params, auths) => {
}
const fs = require("fs")
const { google } = require('googleapis')
const driveAuth = new google.auth.OAuth2()
driveAuth.setCredentials({ access_token: auths.google_drive.oauth_access_token })
const drive = await google.drive({ version: 'v3', auth: driveAuth });
const { fileId, filePath } = params
return drive.files
.get({ fileId, alt: 'media' }, { responseType: 'stream' })
.then(res => {
return new Promise((resolve, reject) => {
console.log(`writing to ${filePath}`);
const dest = fs.createWriteStream(filePath);
let progress = 0;
res.data
.on('end', () => {
console.log('Done downloading file.');
resolve(filePath);
})
.on('error', err => {
console.error('Error downloading file.');
reject(err);
})
.on('data', d => {
progress += d.length;
if (process.stdout.isTTY) {
process.stdout.clearLine();
process.stdout.cursorTo(0);
process.stdout.write(`Downloaded ${progress} bytes`);
}
})
.pipe(dest);
});
});
A list of parent folder IDs, entered manually or retrieved from a previous file list operation
The path to the file, e.g. /tmp/myFile.csv .
async
(params, auths) => {
}
const fs = require("fs")
const {google} = require('googleapis')
const driveAuth = new google.auth.OAuth2()
driveAuth.setCredentials({ access_token: auths.google_drive.oauth_access_token })
const drive = await google.drive({ version: 'v3', auth: driveAuth });
this.uploadResponse = (await drive.files.create({
resource: {
name: params.filename,
originalFilename: params.filename,
parents: params.parents,
},
media: {
mimeType: params.filetype,
uploadType: "media",
body: fs.createReadStream(params.pathToFile)
},
fields: '*'
})).data