npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

capacitor-google-drive

v1.0.1

Published

Google Drive integration for Capacitor

Readme

capacitor-google-drive

Google Drive integration for Capacitor - backup and sync files to Google Drive on Android, iOS, and Web.

Install

npm install capacitor-google-drive
npx cap sync

Platform Support

| Feature | Android | iOS | Web | |---------|:-------:|:---:|:---:| | initialize | ✅ | ✅ | ✅ | | listFiles | ✅ | ✅ | ✅ | | uploadFile | ✅ | ✅ | ✅ | | downloadFile | ✅ | ✅ | ✅ | | updateFile | ✅ | ✅ | ✅ | | deleteFile | ✅ | ✅ | ✅ | | createFolder | ✅ | ✅ | ✅ | | getFileMetadata | ✅ | ✅ | ✅ | | searchFiles | ✅ | ✅ | ✅ |

Configuration & Authentication

Important: This plugin does not handle the OAuth 2.0 login flow. You must obtain a valid OAuth2 Access Token with appropriate Google Drive scopes before using this plugin.

Use a separate authentication plugin (like @capacitor-firebase/authentication, @codetrix-studio/capacitor-google-auth, or similar) to obtain the access token.

Required Scopes

Ensure your auth flow requests one of these scopes:

  • https://www.googleapis.com/auth/drive (Full access)
  • https://www.googleapis.com/auth/drive.file (Access to files created by the app)

Usage Examples

Initialize

Before calling any API methods, you must initialize the plugin with an access token:

import { GoogleDrive } from 'capacitor-google-drive';

const initializeDrive = async (accessToken: string) => {
  try {
    const result = await GoogleDrive.initialize({ accessToken });
    if (result.success) {
      console.log('Google Drive Plugin initialized successfully');
    }
  } catch (error) {
    console.error('Failed to initialize Google Drive:', error);
  }
};

List Files

const listFiles = async () => {
  const response = await GoogleDrive.listFiles({
    pageSize: 10,
    query: "mimeType = 'application/vnd.google-apps.folder'",
    orderBy: "modifiedTime desc"
  });
  
  response.files.forEach(file => {
    console.log(`File: ${file.name} (${file.id})`);
  });
};

Create a Folder

const createFolder = async (folderName: string) => {
  const result = await GoogleDrive.createFolder({
    name: folderName,
    // parentFolderId: 'parent_id' // Optional
  });
  console.log('Created Folder ID:', result.folderId);
};

Upload a File

const uploadFile = async () => {
  const result = await GoogleDrive.uploadFile({
    name: 'backup.json',
    content: JSON.stringify({ data: 'my data' }),
    mimeType: 'application/json',
    folderId: 'optional_folder_id'
  });
  
  console.log('Uploaded File ID:', result.fileId);
};

Download a File

const downloadFile = async (fileId: string) => {
  const result = await GoogleDrive.downloadFile({ fileId });
  console.log('File name:', result.name);
  console.log('Content:', result.content);
};

Update a File

const updateFile = async (fileId: string, newContent: string) => {
  const result = await GoogleDrive.updateFile({
    fileId,
    content: newContent,
    mimeType: 'application/json'
  });
  console.log('Updated File ID:', result.fileId);
};

Delete a File

const deleteFile = async (fileId: string) => {
  const result = await GoogleDrive.deleteFile({ fileId });
  console.log('Deleted:', result.success);
};

Search Files

const searchFiles = async (searchQuery: string) => {
  const result = await GoogleDrive.searchFiles({
    query: `name contains '${searchQuery}'`,
    pageSize: 20
  });
  console.log('Found files:', result.files);
};

Complete Backup Service Example

Here's a complete example of a backup service using this plugin:

import { GoogleDrive } from 'capacitor-google-drive';

const APP_FOLDER_NAME = 'My App Backup';
const BACKUP_FILE_NAME = 'backup.json';

class BackupService {
  private appFolderId: string | null = null;

  async initialize(accessToken: string) {
    await GoogleDrive.initialize({ accessToken });
  }

  async ensureAppFolder(): Promise<string> {
    // Find existing folder
    const response = await GoogleDrive.listFiles({
      query: `name = '${APP_FOLDER_NAME}' and mimeType = 'application/vnd.google-apps.folder' and trashed = false`,
    });

    if (response.files.length > 0) {
      this.appFolderId = response.files[0].id;
      return this.appFolderId;
    }

    // Create new folder
    const result = await GoogleDrive.createFolder({ name: APP_FOLDER_NAME });
    this.appFolderId = result.folderId;
    return this.appFolderId;
  }

  async backup(data: any) {
    await this.ensureAppFolder();
    
    await GoogleDrive.uploadFile({
      name: BACKUP_FILE_NAME,
      content: JSON.stringify(data),
      mimeType: 'application/json',
      folderId: this.appFolderId!,
    });
  }

  async restore(): Promise<any | null> {
    await this.ensureAppFolder();

    const response = await GoogleDrive.listFiles({
      query: `name = '${BACKUP_FILE_NAME}' and '${this.appFolderId}' in parents and trashed = false`,
    });

    if (response.files.length === 0) return null;

    const result = await GoogleDrive.downloadFile({ fileId: response.files[0].id });
    return JSON.parse(result.content);
  }
}

API

initialize(...)

initialize(options: { accessToken: string; }) => Promise<{ success: boolean; }>

Initialize the plugin with Firebase OAuth access token

| Param | Type | | ------------- | ------------------------------------- | | options | { accessToken: string; } |

Returns: Promise<{ success: boolean; }>


listFiles(...)

listFiles(options?: { pageSize?: number | undefined; query?: string | undefined; orderBy?: string | undefined; pageToken?: string | undefined; } | undefined) => Promise<{ files: DriveFile[]; nextPageToken?: string; }>

List files from Google Drive

| Param | Type | | ------------- | ----------------------------------------------------------------------------------------- | | options | { pageSize?: number; query?: string; orderBy?: string; pageToken?: string; } |

Returns: Promise<{ files: DriveFile[]; nextPageToken?: string; }>


uploadFile(...)

uploadFile(options: { name: string; content: string; mimeType: string; folderId?: string; }) => Promise<{ fileId: string; webViewLink: string; }>

Upload a file to Google Drive

| Param | Type | | ------------- | ------------------------------------------------------------------------------------ | | options | { name: string; content: string; mimeType: string; folderId?: string; } |

Returns: Promise<{ fileId: string; webViewLink: string; }>


downloadFile(...)

downloadFile(options: { fileId: string; }) => Promise<{ content: string; name: string; mimeType: string; }>

Download a file from Google Drive

| Param | Type | | ------------- | -------------------------------- | | options | { fileId: string; } |

Returns: Promise<{ content: string; name: string; mimeType: string; }>


updateFile(...)

updateFile(options: { fileId: string; content: string; mimeType: string; }) => Promise<{ fileId: string; webViewLink: string; }>

Update an existing file

| Param | Type | | ------------- | ------------------------------------------------------------------- | | options | { fileId: string; content: string; mimeType: string; } |

Returns: Promise<{ fileId: string; webViewLink: string; }>


deleteFile(...)

deleteFile(options: { fileId: string; }) => Promise<{ success: boolean; }>

Delete a file from Google Drive

| Param | Type | | ------------- | -------------------------------- | | options | { fileId: string; } |

Returns: Promise<{ success: boolean; }>


createFolder(...)

createFolder(options: { name: string; parentFolderId?: string; }) => Promise<{ folderId: string; }>

Create a folder in Google Drive

| Param | Type | | ------------- | ------------------------------------------------------- | | options | { name: string; parentFolderId?: string; } |

Returns: Promise<{ folderId: string; }>


getFileMetadata(...)

getFileMetadata(options: { fileId: string; }) => Promise<{ file: DriveFile; }>

Get file metadata

| Param | Type | | ------------- | -------------------------------- | | options | { fileId: string; } |

Returns: Promise<{ file: DriveFile; }>


searchFiles(...)

searchFiles(options: { query: string; pageSize?: number; }) => Promise<{ files: DriveFile[]; }>

Search for files

| Param | Type | | ------------- | -------------------------------------------------- | | options | { query: string; pageSize?: number; } |

Returns: Promise<{ files: DriveFile[]; }>


Interfaces

DriveFile

| Prop | Type | | -------------------- | --------------------- | | id | string | | name | string | | mimeType | string | | createdTime | string | | modifiedTime | string | | size | string | | webViewLink | string | | webContentLink | string | | iconLink | string | | thumbnailLink | string | | parents | string[] |

License

MIT