{"_id":"@aadvik-teklabs/gdrive-uploader","_rev":"3-27c8887294cecc5fe758a26466e29f7b","name":"@aadvik-teklabs/gdrive-uploader","dist-tags":{"latest":"2.0.2"},"versions":{"2.0.0":{"name":"@aadvik-teklabs/gdrive-uploader","version":"2.0.0","keywords":["google-drive","google-drive-api","file-upload","nestjs","react","nextjs","typescript","drive","storage","cloud-storage","oauth2","pkce","react-hooks","browser"],"author":"","license":"MIT","_id":"@aadvik-teklabs/gdrive-uploader@2.0.0","maintainers":[{"name":"aadvik-teklabs","email":"info@aadviklabs.com"}],"homepage":"https://github.com/AadvikLabs/npm-gdrive-uploder#readme","bugs":{"url":"https://github.com/AadvikLabs/npm-gdrive-uploder/issues"},"dist":{"shasum":"df66a9ff9f286cbdfef01009f6fb05335532fe72","tarball":"https://registry.npmjs.org/@aadvik-teklabs/gdrive-uploader/-/gdrive-uploader-2.0.0.tgz","fileCount":33,"integrity":"sha512-poPJ+ZpcOlkog/hgF0Aghda1402ylfpuREnfClAJRC3tiIx2zVmxNb2bpbp3GoaCoO+XzMvER8+3JBAARPb5LQ==","signatures":[{"sig":"MEQCICeVJXD0A5nDrII06Li+6QeKHJrOIlSNC2WhEMBBUt+jAiB5l5hb6km1SjSTABnJJm6vyRXmoU/xtp3HpAGkqBrL4g==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":107407},"main":"dist/index.js","types":"dist/index.d.ts","engines":{"node":">=16.0.0"},"exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"./react":{"types":"./dist/react/index.d.ts","default":"./dist/react/index.js"},"./nestjs":{"types":"./dist/nestjs/index.d.ts","default":"./dist/nestjs/index.js"},"./browser":{"types":"./dist/browser/index.d.ts","default":"./dist/browser/index.js"}},"gitHead":"e58ab4978b3fa83295a9afa9c747c2f2e88b4251","scripts":{"demo":"node demo/server.js","lint":"eslint \"src/**/*.ts\" --fix","test":"jest","build":"tsc","clean":"rimraf dist","start":"node demo/server.js","format":"prettier --write \"src/**/*.ts\"","prebuild":"npm run clean","test:cov":"jest --coverage","test:watch":"jest --watch","prepublishOnly":"npm run build"},"_npmUser":{"name":"aadvik-teklabs","email":"info@aadviklabs.com"},"repository":{"url":"git+https://github.com/AadvikLabs/npm-gdrive-uploder.git","type":"git"},"_npmVersion":"11.12.1","description":"A comprehensive Google Drive file upload and management library for Node.js, NestJS, React, and Next.js applications","directories":{},"_nodeVersion":"24.15.0","dependencies":{"cors":"^2.8.6","dotenv":"^17.4.2","multer":"^2.1.1","express":"^5.2.1","googleapis":"^152.0.0"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","react":"^18.2.0","eslint":"^9.18.0","rimraf":"^6.1.3","ts-jest":"^29.2.5","prettier":"^3.4.2","react-dom":"^18.2.0","typescript":"^5.7.3","@types/node":"^22.13.1","@nestjs/core":"^11.0.10","@types/react":"^18.2.0","@nestjs/common":"^11.0.10","@types/express":"^5.0.6","@types/react-dom":"^18.2.0","eslint-config-prettier":"^10.0.1","eslint-plugin-prettier":"^5.2.2"},"peerDependencies":{"react":"^17.0.0 || ^18.0.0 || ^19.0.0","react-dom":"^17.0.0 || ^18.0.0 || ^19.0.0","@nestjs/core":"^10.0.0 || ^11.0.0","@nestjs/common":"^10.0.0 || ^11.0.0"},"peerDependenciesMeta":{"react":{"optional":true},"react-dom":{"optional":true},"@nestjs/core":{"optional":true},"@nestjs/common":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/gdrive-uploader_2.0.0_1783078869192_0.09952773279963356","host":"s3://npm-registry-packages-npm-production"}},"2.0.1":{"name":"@aadvik-teklabs/gdrive-uploader","version":"2.0.1","keywords":["google-drive","google-drive-api","file-upload","nestjs","react","nextjs","typescript","drive","storage","cloud-storage","oauth2","pkce","react-hooks","browser"],"author":"","license":"MIT","_id":"@aadvik-teklabs/gdrive-uploader@2.0.1","maintainers":[{"name":"aadvik-teklabs","email":"info@aadviklabs.com"}],"homepage":"https://github.com/AadvikLabs/npm-gdrive-uploder#readme","bugs":{"url":"https://github.com/AadvikLabs/npm-gdrive-uploder/issues"},"dist":{"shasum":"c13e251b9615c858c864d434b3d93c559f978eb7","tarball":"https://registry.npmjs.org/@aadvik-teklabs/gdrive-uploader/-/gdrive-uploader-2.0.1.tgz","fileCount":33,"integrity":"sha512-5vGK1Uu+jpkeNzKkDgx9Iv7BUmR/S3mv5wzb4DyO7ssv2HQEM7uL6NeOvAIt9lYnVObwDJ2kfbmAqip/4mUyPw==","signatures":[{"sig":"MEUCIEJw99TyJDCln/xXhbhFiWWiDxi5nQH84WkHdvzvJx6dAiEApOhRdc9wbYbKn81a7KJfmKLopVNEB9rWnBlXO99Nc/I=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":107411},"main":"dist/index.js","types":"dist/index.d.ts","engines":{"node":">=16.0.0"},"exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"./react":{"types":"./dist/react/index.d.ts","default":"./dist/react/index.js"},"./nestjs":{"types":"./dist/nestjs/index.d.ts","default":"./dist/nestjs/index.js"},"./browser":{"types":"./dist/browser/index.d.ts","default":"./dist/browser/index.js"}},"gitHead":"e58ab4978b3fa83295a9afa9c747c2f2e88b4251","scripts":{"demo":"node demo/server.js","lint":"eslint \"src/**/*.ts\" --fix","test":"jest","build":"tsc","clean":"rimraf dist","start":"node demo/server.js","format":"prettier --write \"src/**/*.ts\"","prebuild":"npm run clean","test:cov":"jest --coverage","test:watch":"jest --watch","prepublishOnly":"npm run build"},"_npmUser":{"name":"aadvik-teklabs","email":"info@aadviklabs.com"},"repository":{"url":"git+https://github.com/AadvikLabs/npm-gdrive-uploder.git","type":"git"},"_npmVersion":"11.12.1","description":"A comprehensive Google Drive file upload and management library for Node.js, NestJS, React, and Next.js applications","directories":{},"_nodeVersion":"24.15.0","dependencies":{"cors":"^2.8.6","dotenv":"^17.4.2","multer":"^2.1.1","express":"^5.2.1","googleapis":"^152.0.0"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","react":"^18.2.0","eslint":"^9.18.0","rimraf":"^6.1.3","ts-jest":"^29.2.5","prettier":"^3.4.2","react-dom":"^18.2.0","typescript":"^5.7.3","@types/node":"^22.13.1","@nestjs/core":"^11.0.10","@types/react":"^18.2.0","@nestjs/common":"^11.0.10","@types/express":"^5.0.6","@types/react-dom":"^18.2.0","eslint-config-prettier":"^10.0.1","eslint-plugin-prettier":"^5.2.2"},"peerDependencies":{"react":"^17.0.0 || ^18.0.0 || ^19.0.0","react-dom":"^17.0.0 || ^18.0.0 || ^19.0.0","@nestjs/core":"^10.0.0 || ^11.0.0","@nestjs/common":"^10.0.0 || ^11.0.0"},"peerDependenciesMeta":{"react":{"optional":true},"react-dom":{"optional":true},"@nestjs/core":{"optional":true},"@nestjs/common":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/gdrive-uploader_2.0.1_1783080194668_0.5181669848951522","host":"s3://npm-registry-packages-npm-production"}},"2.0.2":{"name":"@aadvik-teklabs/gdrive-uploader","version":"2.0.2","description":"A comprehensive Google Drive file upload and management library for Node.js, NestJS, React, and Next.js applications","author":"","license":"MIT","main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"./nestjs":{"types":"./dist/nestjs/index.d.ts","default":"./dist/nestjs/index.js"},"./browser":{"types":"./dist/browser/index.d.ts","default":"./dist/browser/index.js"},"./react":{"types":"./dist/react/index.d.ts","default":"./dist/react/index.js"}},"keywords":["google-drive","google-drive-api","file-upload","nestjs","react","nextjs","typescript","drive","storage","cloud-storage","oauth2","pkce","react-hooks","browser"],"repository":{"type":"git","url":"git+https://github.com/AadvikLabs/npm-gdrive-uploder.git"},"bugs":{"url":"https://github.com/AadvikLabs/npm-gdrive-uploder/issues"},"homepage":"https://github.com/AadvikLabs/npm-gdrive-uploder#readme","scripts":{"build":"tsc","clean":"rimraf dist","prebuild":"npm run clean","start":"node demo/server.js","demo":"node demo/server.js","prepublishOnly":"npm run build","format":"prettier --write \"src/**/*.ts\"","lint":"eslint \"src/**/*.ts\" --fix","test":"jest","test:watch":"jest --watch","test:cov":"jest --coverage"},"dependencies":{"cors":"^2.8.6","dotenv":"^17.4.2","express":"^5.2.1","googleapis":"^152.0.0","multer":"^2.1.1"},"peerDependencies":{"@nestjs/common":"^10.0.0 || ^11.0.0","@nestjs/core":"^10.0.0 || ^11.0.0","react":"^17.0.0 || ^18.0.0 || ^19.0.0","react-dom":"^17.0.0 || ^18.0.0 || ^19.0.0"},"peerDependenciesMeta":{"@nestjs/common":{"optional":true},"@nestjs/core":{"optional":true},"react":{"optional":true},"react-dom":{"optional":true}},"devDependencies":{"@nestjs/common":"^11.0.10","@nestjs/core":"^11.0.10","@types/express":"^5.0.6","@types/node":"^22.13.1","@types/react":"^18.2.0","@types/react-dom":"^18.2.0","eslint":"^9.18.0","eslint-config-prettier":"^10.0.1","eslint-plugin-prettier":"^5.2.2","jest":"^29.7.0","prettier":"^3.4.2","react":"^18.2.0","react-dom":"^18.2.0","rimraf":"^6.1.3","ts-jest":"^29.2.5","typescript":"^5.7.3"},"engines":{"node":">=16.0.0"},"gitHead":"565fade4bbeffc11b6e2e05fe5fdaff33d197aa8","_id":"@aadvik-teklabs/gdrive-uploader@2.0.2","_nodeVersion":"24.15.0","_npmVersion":"11.12.1","dist":{"integrity":"sha512-SHQx6zKkkwFJ5zGtg3FuJoXcxIPhuYIBXwgSUg4jOD2vFmGzdgKuU810/HQq4WmWFbv7vX5jbpzskdIJ3M1L6g==","shasum":"e99bba5046c86760fce0e21771fe9a1f325a5086","tarball":"https://registry.npmjs.org/@aadvik-teklabs/gdrive-uploader/-/gdrive-uploader-2.0.2.tgz","fileCount":33,"unpackedSize":107578,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIHdDfJAuLMRPECj+peBskZXBUKCVeEVKv/PacmE2f1paAiEAzfOlDqVqxMEH2Z+dAKqHVbjNqi26+jw/10MSz+DEgDQ="}]},"_npmUser":{"name":"aadvik-teklabs","email":"info@aadviklabs.com"},"directories":{},"maintainers":[{"name":"aadvik-teklabs","email":"info@aadviklabs.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/gdrive-uploader_2.0.2_1783081438531_0.5527492474258457"},"_hasShrinkwrap":false}},"time":{"created":"2026-07-03T11:41:09.034Z","modified":"2026-07-03T12:23:58.777Z","2.0.0":"2026-07-03T11:41:09.356Z","2.0.1":"2026-07-03T12:03:14.828Z","2.0.2":"2026-07-03T12:23:58.661Z"},"bugs":{"url":"https://github.com/AadvikLabs/npm-gdrive-uploder/issues"},"license":"MIT","homepage":"https://github.com/AadvikLabs/npm-gdrive-uploder#readme","keywords":["google-drive","google-drive-api","file-upload","nestjs","react","nextjs","typescript","drive","storage","cloud-storage","oauth2","pkce","react-hooks","browser"],"repository":{"type":"git","url":"git+https://github.com/AadvikLabs/npm-gdrive-uploder.git"},"description":"A comprehensive Google Drive file upload and management library for Node.js, NestJS, React, and Next.js applications","maintainers":[{"name":"aadvik-teklabs","email":"info@aadviklabs.com"}],"readme":"﻿# @aadvik-teklabs/gdrive-uploader\r\n\r\nA comprehensive, production-ready Google Drive file upload and management library for **Node.js**, **NestJS**, **React**, and **Next.js** applications.\r\n\r\n## Features\r\n\r\nâœ¨ **Easy to Use** - Simple API with TypeScript support\r\nðŸ“¦ **Multi-Platform** - Works in Node.js backend, React, and Next.js\r\nðŸŒ **Browser Support** - Client-side Google Drive integration with OAuth2 PKCE\r\nðŸ”’ **Secure** - OAuth2 authentication (server-side with refresh tokens, client-side with PKCE)\r\nðŸ“ **Folder Management** - Create, organize, and manage folders\r\nðŸ” **Search & List** - Search files and list folder contents\r\nï¿½ **React Hooks** - Pre-built hooks for easy React integration\r\nðŸ§© **NestJS Module** - Injectable service for NestJS applications\r\nðŸ”— **Public/Private Files** - Control file visibility\r\nâš¡ **TypeScript First** - Written in TypeScript with full type definitions\r\nðŸŽ¯ **Production Ready** - Battle-tested in production environments\r\n\r\n## Installation\r\n\r\n```bash\r\nnpm install @aadvik-teklabs/gdrive-uploader\r\n```\r\n\r\nFor React/Next.js projects, also install peer dependencies:\r\n\r\n```bash\r\nnpm install react react-dom\r\n```\r\n\r\n## Table of Contents\r\n\r\n- [Node.js / Backend Usage](#nodejs--backend-usage)\r\n- [React Usage](#react-usage)\r\n- [Next.js Usage](#nextjs-usage)\r\n- [Browser Usage](#browser-usage)\r\n- [NestJS Usage](#nestjs-usage)\r\n- [Google OAuth Setup](#google-oauth-setup)\r\n- [Security Best Practices](#security-best-practices)\r\n- [API Reference](#api-reference)\r\n\r\n---\r\n\r\n## Node.js / Backend Usage\r\n\r\n### Quick Start\r\n\r\n```typescript\r\nimport { GoogleDriveStorage } from '@aadvik-teklabs/gdrive-uploader';\r\n\r\nconst driveStorage = new GoogleDriveStorage({\r\n  clientId: process.env.GOOGLE_CLIENT_ID,\r\n  clientSecret: process.env.GOOGLE_CLIENT_SECRET,\r\n  refreshToken: process.env.GOOGLE_REFRESH_TOKEN,\r\n});\r\n\r\n// Upload a file\r\nconst result = await driveStorage.uploadFile(fileBuffer, 'hello.txt', {\r\n  folder: 'my-uploads',\r\n});\r\n\r\nconsole.log('File uploaded:', result.fileId);\r\n```\r\n\r\n### Available Methods\r\n\r\n```typescript\r\n// Upload file\r\nawait driveStorage.uploadFile(buffer, 'file.pdf', { folder: 'Documents' });\r\n\r\n// Download file\r\nconst buffer = await driveStorage.downloadFile(fileId);\r\n\r\n// List files\r\nconst files = await driveStorage.listFiles({ folderId: 'folder-id' });\r\n\r\n// Search files\r\nconst results = await driveStorage.searchFiles({ query: 'report' });\r\n\r\n// Delete file\r\nawait driveStorage.deleteFile(fileId);\r\n\r\n// Create folder\r\nconst folderId = await driveStorage.createFolder('My Folder');\r\n```\r\n\r\n---\r\n\r\n## React Usage\r\n\r\n### 1. Setup Provider\r\n\r\nWrap your app with `GoogleDriveProvider`:\r\n\r\n```tsx\r\nimport { GoogleDriveProvider } from '@aadvik-teklabs/gdrive-uploader/react';\r\n\r\nfunction App() {\r\n  return (\r\n    <GoogleDriveProvider\r\n      config={{\r\n        clientId: 'YOUR_GOOGLE_CLIENT_ID',\r\n        redirectUri: window.location.origin + '/auth/callback',\r\n        scopes: [\r\n          'https://www.googleapis.com/auth/drive.file',\r\n          'https://www.googleapis.com/auth/userinfo.email',\r\n        ],\r\n      }}\r\n    >\r\n      <YourApp />\r\n    </GoogleDriveProvider>\r\n  );\r\n}\r\n```\r\n\r\n### 2. Use Authentication Hook\r\n\r\n```tsx\r\nimport { useGoogleAuth } from '@aadvik-teklabs/gdrive-uploader/react';\r\n\r\nfunction AuthButton() {\r\n  const { isAuthenticated, userEmail, signIn, signOut } = useGoogleAuth();\r\n\r\n  if (isAuthenticated) {\r\n    return (\r\n      <div>\r\n        <span>Signed in as: {userEmail}</span>\r\n        <button onClick={() => signOut()}>Sign Out</button>\r\n      </div>\r\n    );\r\n  }\r\n\r\n  return <button onClick={() => signIn(true)}>Sign in with Google</button>;\r\n}\r\n```\r\n\r\n### 3. Upload Files\r\n\r\n```tsx\r\nimport { FileUploader } from '@aadvik-teklabs/gdrive-uploader/react';\r\n\r\nfunction UploadPage() {\r\n  return (\r\n    <FileUploader\r\n      uploadOptions={{\r\n        folder: 'My Uploads',\r\n        makePublic: false,\r\n      }}\r\n      onUploadComplete={(fileId, fileName) => {\r\n        console.log('Uploaded:', fileName);\r\n      }}\r\n      showProgress={true}\r\n    />\r\n  );\r\n}\r\n```\r\n\r\n### 4. List and Manage Files\r\n\r\n```tsx\r\nimport { useFileList, useFileDelete } from '@aadvik-teklabs/gdrive-uploader/react';\r\n\r\nfunction FileList() {\r\n  const { files, isLoading, loadFiles, refresh } = useFileList();\r\n  const { deleteFile } = useFileDelete();\r\n\r\n  useEffect(() => {\r\n    loadFiles();\r\n  }, []);\r\n\r\n  return (\r\n    <div>\r\n      {files.map((file) => (\r\n        <div key={file.id}>\r\n          <span>{file.name}</span>\r\n          <button onClick={() => deleteFile(file.id)}>Delete</button>\r\n        </div>\r\n      ))}\r\n    </div>\r\n  );\r\n}\r\n```\r\n\r\n### Available React Hooks\r\n\r\n- `useGoogleAuth()` - Authentication state and methods\r\n- `useFileUpload()` - File upload with progress tracking\r\n- `useFileDownload()` - Download files\r\n- `useFileList()` - List files with pagination\r\n- `useFileSearch()` - Search files\r\n- `useFileDelete()` - Delete files\r\n- `useFolderOperations()` - Create and manage folders\r\n\r\n---\r\n\r\n## Next.js Usage\r\n\r\n### App Router (Next.js 13+)\r\n\r\n#### 1. Create Layout with Provider\r\n\r\n```tsx\r\n// app/layout.tsx\r\n'use client';\r\n\r\nimport { GoogleDriveProvider } from '@aadvik-teklabs/gdrive-uploader/react';\r\n\r\nexport default function RootLayout({ children }) {\r\n  return (\r\n    <html>\r\n      <body>\r\n        <GoogleDriveProvider\r\n          config={{\r\n            clientId: process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID!,\r\n            redirectUri: process.env.NEXT_PUBLIC_REDIRECT_URI!,\r\n          }}\r\n        >\r\n          {children}\r\n        </GoogleDriveProvider>\r\n      </body>\r\n    </html>\r\n  );\r\n}\r\n```\r\n\r\n#### 2. Create OAuth Callback Page\r\n\r\n```tsx\r\n// app/auth/callback/page.tsx\r\n'use client';\r\n\r\nimport { useEffect } from 'react';\r\nimport { useRouter } from 'next/navigation';\r\nimport { useGoogleDriveContext } from '@aadvik-teklabs/gdrive-uploader/react';\r\n\r\nexport default function CallbackPage() {\r\n  const router = useRouter();\r\n  const { handleCallback } = useGoogleDriveContext();\r\n\r\n  useEffect(() => {\r\n    handleCallback().then(() => router.push('/'));\r\n  }, []);\r\n\r\n  return <div>Processing authentication...</div>;\r\n}\r\n```\r\n\r\n### Pages Router\r\n\r\nSee [examples/nextjs/pages-router-example.tsx](examples/nextjs/pages-router-example.tsx) for complete example.\r\n\r\n### Server-Side API Routes\r\n\r\nCreate API routes for server-side operations:\r\n\r\n```typescript\r\n// pages/api/drive/upload.ts\r\nimport { GoogleDriveStorage } from '@aadvik-teklabs/gdrive-uploader';\r\n\r\nexport default async function handler(req, res) {\r\n  const drive = new GoogleDriveStorage({\r\n    clientId: process.env.GOOGLE_CLIENT_ID!,\r\n    clientSecret: process.env.GOOGLE_CLIENT_SECRET!,\r\n    refreshToken: process.env.GOOGLE_REFRESH_TOKEN!,\r\n  });\r\n\r\n  const result = await drive.uploadFile(fileBuffer, fileName);\r\n  res.json(result);\r\n}\r\n```\r\n\r\n---\r\n\r\n## Browser Usage\r\n\r\nFor vanilla JavaScript or other frameworks:\r\n\r\n```typescript\r\nimport { GoogleDriveBrowser } from '@aadvik-teklabs/gdrive-uploader/browser';\r\n\r\nconst drive = new GoogleDriveBrowser({\r\n  clientId: 'YOUR_CLIENT_ID',\r\n  redirectUri: window.location.origin + '/callback',\r\n});\r\n\r\n// Sign in\r\nawait drive.signIn(true); // true = use popup\r\n\r\n// Upload file\r\nconst fileInput = document.querySelector('input[type=\"file\"]');\r\nconst file = fileInput.files[0];\r\nconst result = await drive.uploadFile(file, {\r\n  folder: 'Uploads',\r\n});\r\n\r\nconsole.log('Uploaded:', result.fileId);\r\n```\r\n\r\n---\r\n\r\n## NestJS Usage\r\n\r\n### 1. Import Module\r\n\r\n```typescript\r\nimport { GoogleDriveModule } from '@aadvik-teklabs/gdrive-uploader';\r\n\r\n@Module({\r\n  imports: [\r\n    GoogleDriveModule.register({\r\n      config: {\r\n        clientId: process.env.GOOGLE_CLIENT_ID!,\r\n        clientSecret: process.env.GOOGLE_CLIENT_SECRET!,\r\n        refreshToken: process.env.GOOGLE_REFRESH_TOKEN!,\r\n      },\r\n      isGlobal: true,\r\n    }),\r\n  ],\r\n})\r\nexport class AppModule {}\r\n```\r\n\r\n### 2. Inject Service\r\n\r\n```typescript\r\nimport { GoogleDriveService } from '@aadvik-teklabs/gdrive-uploader';\r\n\r\n@Injectable()\r\nexport class FileService {\r\n  constructor(private readonly driveService: GoogleDriveService) {}\r\n\r\n  async uploadFile(file: Express.Multer.File) {\r\n    return this.driveService.uploadFile(file.buffer, file.originalname, {\r\n      folder: 'uploads',\r\n    });\r\n  }\r\n}\r\n```\r\n\r\n---\r\n\r\n## Google OAuth Setup\r\n\r\n### For Backend (Node.js/NestJS)\r\n\r\n1. Go to [Google Cloud Console](https://console.cloud.google.com/)\r\n2. Create a new project or select existing\r\n3. Enable **Google Drive API**\r\n4. Create **OAuth 2.0 Client ID** credentials\r\n5. Add authorized redirect URIs (e.g., `http://localhost:3000/oauth2callback`)\r\n6. Get your **Client ID**, **Client Secret**, and **Refresh Token**\r\n\r\n#### Getting Refresh Token\r\n\r\nUse the [OAuth 2.0 Playground](https://developers.google.com/oauthplayground/):\r\n\r\n1. Click settings (âš™ï¸) and check \"Use your own OAuth credentials\"\r\n2. Enter your Client ID and Client Secret\r\n3. Select scopes: `https://www.googleapis.com/auth/drive.file`\r\n4. Click \"Authorize APIs\"\r\n5. Exchange authorization code for tokens\r\n6. Copy the **Refresh Token**\r\n\r\n### For Frontend (React/Next.js/Browser)\r\n\r\n1. Go to [Google Cloud Console](https://console.cloud.google.com/)\r\n2. Create **OAuth 2.0 Client ID** for **Web application**\r\n3. Add authorized JavaScript origins:\r\n   - `http://localhost:3000` (development)\r\n   - `https://yourdomain.com` (production)\r\n4. Add authorized redirect URIs:\r\n   - `http://localhost:3000/auth/callback` (development)\r\n   - `https://yourdomain.com/auth/callback` (production)\r\n5. Copy your **Client ID** (âš ï¸ **DO NOT** use Client Secret in frontend!)\r\n\r\n### Environment Variables\r\n\r\nCreate a `.env` file:\r\n\r\n```bash\r\n# Backend (Node.js/NestJS)\r\nGOOGLE_CLIENT_ID=your-client-id\r\nGOOGLE_CLIENT_SECRET=your-client-secret\r\nGOOGLE_REFRESH_TOKEN=your-refresh-token\r\nGOOGLE_ROOT_FOLDER_ID=optional-folder-id\r\n\r\n# Frontend (React/Next.js)\r\nNEXT_PUBLIC_GOOGLE_CLIENT_ID=your-client-id\r\nNEXT_PUBLIC_REDIRECT_URI=http://localhost:3000/auth/callback\r\n```\r\n\r\n---\r\n\r\n## Security Best Practices\r\n\r\n### âœ… DO\r\n\r\n- **Backend**: Use Client Secret and Refresh Token (server-side only)\r\n- **Frontend**: Use OAuth2 PKCE flow (no client secret required)\r\n- Store tokens in `sessionStorage` (not `localStorage` for better security)\r\n- Use environment variables for sensitive credentials\r\n- Limit OAuth scopes to minimum required:\r\n  - `https://www.googleapis.com/auth/drive.file` - Access only files created by the app\r\n  - `https://www.googleapis.com/auth/drive` - Full Drive access (use cautiously)\r\n- Validate file types and sizes before upload\r\n- Use HTTPS in production\r\n- Implement rate limiting on API routes\r\n\r\n### âŒ DON'T\r\n\r\n- **Never** expose Client Secret in frontend code\r\n- **Never** commit credentials to version control\r\n- **Never** use Refresh Tokens in browser/frontend\r\n- **Never** store sensitive tokens in `localStorage` (vulnerable to XSS)\r\n- **Never** grant more OAuth scopes than necessary\r\n\r\n### Architecture Recommendations\r\n\r\n#### Option 1: Client-Side Only (Simple)\r\n\r\n- Use `@aadvik-teklabs/gdrive-uploader/browser` or `/react`\r\n- User authenticates with their own Google account\r\n- Files are uploaded directly from browser to Google Drive\r\n- âœ… Simple, no backend needed\r\n- âŒ User must sign in with Google\r\n- âŒ Limited control over file organization\r\n\r\n#### Option 2: Server-Side Proxy (Recommended for Production)\r\n\r\n- Frontend sends files to your API\r\n- Backend uses service account or OAuth to upload to Drive\r\n- âœ… Full control over file organization\r\n- âœ… Can implement additional validation/processing\r\n- âœ… Users don't need Google accounts\r\n- âŒ Requires backend infrastructure\r\n\r\n#### Option 3: Hybrid (Best of Both)\r\n\r\n- Use client-side for user-specific files\r\n- Use server-side for shared/organizational files\r\n- âœ… Maximum flexibility\r\n- âŒ More complex setup\r\n\r\n---\r\n\r\n## API Reference\r\n\r\n### Node.js / Backend\r\n\r\n#### `GoogleDriveStorage`\r\n\r\n```typescript\r\nclass GoogleDriveStorage {\r\n  constructor(config: GoogleDriveConfig);\r\n\r\n  uploadFile(buffer: Buffer, fileName: string, options?: UploadOptions): Promise<UploadResult>;\r\n  downloadFile(fileId: string): Promise<Buffer>;\r\n  deleteFile(fileId: string): Promise<void>;\r\n  getFileMetadata(fileId: string): Promise<FileMetadata>;\r\n  listFiles(options?: ListOptions): Promise<FileMetadata[]>;\r\n  searchFiles(options: SearchOptions): Promise<FileMetadata[]>;\r\n  createFolder(folderName: string, parentId?: string): Promise<string>;\r\n  getOrCreateFolder(folderName: string, parentId?: string): Promise<string>;\r\n  makeFilePublic(fileId: string): Promise<void>;\r\n}\r\n```\r\n\r\n### Browser\r\n\r\n#### `GoogleDriveBrowser`\r\n\r\n```typescript\r\nclass GoogleDriveBrowser {\r\n  constructor(config: GoogleDriveBrowserConfig);\r\n\r\n  signIn(usePopup?: boolean): Promise<void>;\r\n  signOut(): Promise<void>;\r\n  handleAuthCallback(url?: string): Promise<void>;\r\n  isAuthenticated(): boolean;\r\n\r\n  uploadFile(file: File, options?: BrowserUploadOptions): Promise<BrowserUploadResult>;\r\n  downloadFile(fileId: string): Promise<Blob>;\r\n  deleteFile(fileId: string): Promise<void>;\r\n  getFileMetadata(fileId: string): Promise<BrowserFileMetadata>;\r\n  listFiles(options?: BrowserListOptions): Promise<BrowserListResponse>;\r\n  searchFiles(options: BrowserSearchOptions): Promise<BrowserFileMetadata[]>;\r\n  createFolder(folderName: string, options?: CreateFolderOptions): Promise<string>;\r\n  getStorageQuota(): Promise<StorageQuota>;\r\n}\r\n```\r\n\r\n### React Hooks\r\n\r\nSee [React Usage](#react-usage) section for hook documentation.\r\n\r\n---\r\n\r\n## Examples\r\n\r\n- [Node.js Standalone](examples/standalone-example.ts)\r\n- [NestJS Integration](examples/nestjs-example.ts)\r\n- [React Complete App](examples/react/complete-example.tsx)\r\n- [Next.js App Router](examples/nextjs/app-router-example.tsx)\r\n- [Next.js Pages Router](examples/nextjs/pages-router-example.tsx)\r\n- [Next.js API Routes](examples/nextjs/api-route-example.ts)\r\n\r\n---\r\n\r\n## Troubleshooting\r\n\r\n### \"Not authenticated\" error in browser\r\n\r\nMake sure you've called `signIn()` before attempting file operations.\r\n\r\n### \"Invalid grant\" error\r\n\r\nYour refresh token may have expired. Generate a new one using OAuth Playground.\r\n\r\n### CORS errors in browser\r\n\r\nEnsure your domain is added to \"Authorized JavaScript origins\" in Google Cloud Console.\r\n\r\n### Popup blocked\r\n\r\nIf using popup sign-in, ensure popups are allowed for your domain. Alternatively, use redirect flow: `signIn(false)`.\r\n\r\n### TypeScript errors with React\r\n\r\nMake sure you have `@types/react` installed:\r\n\r\n```bash\r\nnpm install --save-dev @types/react @types/react-dom\r\n```\r\n\r\n---\r\n\r\n## Contributing\r\n\r\nContributions are welcome! Please open an issue or submit a pull request.\r\n\r\n## License\r\n\r\nMIT Â© Aadvik Labs\r\n\r\n## Support\r\n\r\nFor issues and questions:\r\n\r\n- GitHub Issues: [https://github.com/AadvikLabs/gdrive-asset-uploader-/issues](https://github.com/AadvikLabs/gdrive-asset-uploader-/issues)\r\n- Documentation: [https://github.com/AadvikLabs/gdrive-asset-uploader-](https://github.com/AadvikLabs/gdrive-asset-uploader-)\r\n\r\n---\r\n\r\n**Made with â¤ï¸ by Aadvik Labs**\r\n","readmeFilename":"README.md"}