zohodrive-asset-uploader
v1.0.0
Published
API to upload images and PDFs to Zoho WorkDrive
Readme
🚀 Zoho WorkDrive Asset Uploader
This project is a Node.js API that connects an application with Zoho WorkDrive. It handles Zoho’s OAuth2 authentication process and provides easy REST APIs to upload, view, and download files like images and PDFs. The main goal of this project is to make file management simple and secure while reducing the complexity of authentication for developers.
✨ Features
Easy Authentication: The system automatically manages Zoho OAuth2 login and refreshes tokens in the background, so no manual work is needed.
Supports Multiple Regions: It works with both India (.in) and Global (.com) Zoho data centers.
Supports Many File Types: You can upload and manage files like JPG, PNG, WEBP, SVG, and PDF easily.
Efficient File Handling: Files can be viewed and downloaded directly from Zoho using streaming, which helps save server memory.
Simple API Testing: Swagger UI is included, so you can test all API endpoints without building a frontend.
🛠️ Setup & Installation
1. Prerequisites
- A Zoho account (Self Client registered in Zoho API Console)
- Generate yor client secret, client id and object id from the self clien id
2. Installation
git clone https://github.com/AadvikLabs/Zohodrive-Asset-Uploader.git
cd Zohodrive-Asset-Uploader
npm install3. Environment Configuration (.env)
Create a .env file in the root directory and fill in your Zoho credentials:
PORT=3000
# Zoho API Credentials
ZOHO_CLIENT_ID=YOUR_CLIENT_ID
ZOHO_CLIENT_SECRET=YOUR_CLIENT_SECRET
ZOHO_FOLDER_ID=YOUR_TARGET_FOLDER_ID
* once you the upper required id you can create the refresh token from the terminal
# Domain Setup (Use .in for India, .com for Global)
ZOHO_ACCOUNTS_URL=https://accounts.zoho.in
on scope write
WorkDrive.files.ALL,WorkDrive.team.READ,WorkDrive.workspace.READ,ZohoFiles.files.ALL
press the generate code button past copy the token and past that in the terminal
### 4. Generate Your Refresh Token
We've included a helper script to make the one-time authentication setup easy:
1. Run the script:
-> node scripts/generateToken.js
2. Copy the token at the terminal
3. The new refresh token will generate which has no expiry date
---
## ▶️ Running the App
**Development Mode:**
```bash
npm run devProduction Mode:
npm startInteractive API Docs:
Open http://localhost:3000/api-docs to test the API directly from your browser.
📡 API Endpoints
| Method | Endpoint | Description |
| :--- | :--- | :--- |
| POST | /api/upload | Upload a file. Returns an attachmentId. |
| GET | /api/view/:id | View a file directly in the browser tab. |
| GET | /api/download/:id | Download a file with its original filename. |
🏗️ Project Structure
- /src/controllers: Logic for handling requests and responses.
- /src/services: The core
ZohoServicewhich manages the OAuth singleton and Zoho API requests. - /src/routes: API endpoint definitions.
- /scripts/generateToken: Setup utilities (Token generator).
- swagger.yaml: OpenAPI 3.0 contract.
📦 Usage as an npm package
You can consume this project as a library instead of running the bundled server. Example usage:
Install your local tarball or publish and install from the registry.
Minimal Express mounting example:
const express = require('express');
const { createApp } = require('zohodrive-asset-uploader'); // or local path to the package
const app = createApp({ mountPath: '/api' });
app.listen(3000, () => console.log('Listening on 3000'));- Programmatic access to services:
const { zohoService } = require('zohodrive-asset-uploader');
// Use zohoService.uploadToWorkDrive(...) or zohoService.getFileStream(...)When used as a package, the host application must provide the required environment variables (see the Configuration section above) so the SDK can authenticate with Zoho.
� Security & Reliability
- Encapsulation: Zoho access tokens are cached in-memory and never exposed or logged.
- Error Resiliency: Custom error handling prevents circular-reference crashes during networking issues.
- Singleton Pattern: Ensures only one authentication state exists across your entire app instance.
