Skip to content

Instantly share code, notes, and snippets.

@noskla
Created August 28, 2023 07:16
Show Gist options
  • Save noskla/74ea927850f2370994ec7ad0deb0d008 to your computer and use it in GitHub Desktop.
Save noskla/74ea927850f2370994ec7ad0deb0d008 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const process = require('process');
const { authenticate } = require('@google-cloud/local-auth');
const { google } = require('googleapis');
const SCOPES = ['https://www.googleapis.com/auth/drive'];
const credentials = JSON.parse(fs.readFileSync('./clientsecret.json'));
console.log('Auth...')
const auth = new google.auth.GoogleAuth({
scopes: SCOPES,
credentials,
});
console.log('Init GDrive...')
const dS = google.drive({version: 'v3', auth});
let fileMetadata = {
name: process.argv[2],
mimeType: 'application/x-7z-compressed'
};
let media = {
mimeType: 'application/x-7z-compressed',
body: fs.createReadStream(process.argv[2]),
};
console.log(process.argv[2]);
console.log('Upload...')
dS.files.create({
resource: fileMetadata,
media: media,
fields: 'id',
}).then(async response => {
dS.files.update({
fileId: response.data.id,
addParents: 'PARENT_FOLDER_ID',
fields: 'id, parents'
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment