Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@googleapis/drive

Package Overview
Dependencies
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@googleapis/drive

drive

  • 8.14.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
116K
decreased by-0.67%
Maintainers
2
Weekly downloads
 
Created

What is @googleapis/drive?

@googleapis/drive is an npm package that provides a client library for accessing Google Drive API. It allows developers to interact with Google Drive to perform various operations such as file management, permissions handling, and more.

What are @googleapis/drive's main functionalities?

List Files

This feature allows you to list files in the user's Google Drive. The code sample demonstrates how to authenticate and list the first 10 files, displaying their IDs and names.

const { google } = require('@googleapis/drive');
const auth = new google.auth.GoogleAuth({
  scopes: ['https://www.googleapis.com/auth/drive.readonly'],
});
async function listFiles() {
  const authClient = await auth.getClient();
  const drive = google.drive({ version: 'v3', auth: authClient });
  const res = await drive.files.list({
    pageSize: 10,
    fields: 'files(id, name)',
  });
  console.log('Files:', res.data.files);
}
listFiles().catch(console.error);

Upload File

This feature allows you to upload a file to Google Drive. The code sample demonstrates how to authenticate, create file metadata, and upload a file from the local filesystem.

const { google } = require('@googleapis/drive');
const fs = require('fs');
const auth = new google.auth.GoogleAuth({
  scopes: ['https://www.googleapis.com/auth/drive.file'],
});
async function uploadFile() {
  const authClient = await auth.getClient();
  const drive = google.drive({ version: 'v3', auth: authClient });
  const fileMetadata = {
    name: 'photo.jpg',
  };
  const media = {
    mimeType: 'image/jpeg',
    body: fs.createReadStream('files/photo.jpg'),
  };
  const res = await drive.files.create({
    resource: fileMetadata,
    media: media,
    fields: 'id',
  });
  console.log('File Id:', res.data.id);
}
uploadFile().catch(console.error);

Create Folder

This feature allows you to create a new folder in Google Drive. The code sample demonstrates how to authenticate and create a folder with specified metadata.

const { google } = require('@googleapis/drive');
const auth = new google.auth.GoogleAuth({
  scopes: ['https://www.googleapis.com/auth/drive.file'],
});
async function createFolder() {
  const authClient = await auth.getClient();
  const drive = google.drive({ version: 'v3', auth: authClient });
  const fileMetadata = {
    name: 'New Folder',
    mimeType: 'application/vnd.google-apps.folder',
  };
  const res = await drive.files.create({
    resource: fileMetadata,
    fields: 'id',
  });
  console.log('Folder Id:', res.data.id);
}
createFolder().catch(console.error);

Delete File

This feature allows you to delete a file from Google Drive. The code sample demonstrates how to authenticate and delete a file by its ID.

const { google } = require('@googleapis/drive');
const auth = new google.auth.GoogleAuth({
  scopes: ['https://www.googleapis.com/auth/drive.file'],
});
async function deleteFile(fileId) {
  const authClient = await auth.getClient();
  const drive = google.drive({ version: 'v3', auth: authClient });
  await drive.files.delete({
    fileId: fileId,
  });
  console.log('File deleted');
}
deleteFile('your-file-id').catch(console.error);

Other packages similar to @googleapis/drive

Keywords

FAQs

Package last updated on 29 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc