@ziqx/drive
v0.0.5
Published
SDK for Ziqx Drive upload and sign URL
Readme
@ziqx/drive
Official SDK for Ziqx Drive — generate signed upload URLs and upload files easily.
📄 Official Docs
Features
- Generate signed URLs for secure file uploads & deletions (server-side)
- Support for folders/paths in uploads and deletions
- Upload files directly from the browser using signed URLs
- Written in TypeScript with full type safety
- Easy integration with React, Next.js, or any Node.js backend
Installation
# Using npm
npm install @ziqx/drive
# Using yarn
yarn add @ziqx/driveUsage
1. Server-side: Generate Signed URLs (ZDrive)
import { ZDrive } from "@ziqx/drive";
async function generateSignedUrl() {
// Initialize with your Drive credentials
const drive = new ZDrive("your-drive-key", "your-drive-secret");
// Generate signed URL for a file (can specify an optional folder)
const signed = await drive.generatePutUrl("example.jpg", "vacation/2024");
if (signed.success && signed.url) {
console.log("✅ Signed URL:", signed.url);
} else {
console.error("❌ Error generating URL:", signed.message);
}
// Delete a file
const deleted = await drive.deleteFile("example.jpg", "vacation/2024");
console.log("Deleted:", deleted);
}
generateSignedUrl();Use this signed URL to upload files directly from the browser.
2. Client-side: Upload Files (ZDriveClient)
import { ZDriveClient } from "@ziqx/drive";
// Example: handling file upload from an <input type="file" />
async function handleUpload(file: File, signedUrl: string) {
const client = new ZDriveClient();
const response = await client.uploadFile(signedUrl, file);
if (response.success) {
console.log("✅ File uploaded:", response.filename);
} else {
console.error("❌ Upload failed:", response.message);
}
}
// Usage: triggered when user selects a file
const fileInput = document.getElementById("fileInput") as HTMLInputElement;
fileInput.addEventListener("change", async () => {
if (fileInput.files?.length) {
// Assume `signedUrl` comes from your backend
const signedUrl = await fetch("/api/drive/sign-url")
.then((res) => res.json())
.then((r) => r.url);
await handleUpload(fileInput.files[0], signedUrl);
}
});Compress Image
const client = new ZDriveClient();
const resizedImage = await client.resizeImage(file);API
ZDrive
| Method | Description | Parameters | Returns |
| --------------------------------------------------- | --------------------------------- | --------------------------------------------- | -------------------------- |
| generatePutUrl(fileName: string, folder?: string) | Generates a signed URL for a file | fileName: Namefolder: Path (Optional) | Promise<SignUrlResponse> |
| deleteFile(fileName: string, folder?: string) | Deletes a file from Ziqx Drive | fileName: Namefolder: Path (Optional) | Promise<UploadResponse> |
ZDriveClient
| Method | Description | Parameters | Returns |
| ------------------------------------------- | ------------------------------------- | ---------------------------------------------------------- | ------------------------- |
| uploadFile(uploadUrl: string, file: File) | Uploads a file directly to Ziqx Drive | uploadUrl — Signed URLfile — Browser File object | Promise<UploadResponse> |
Response Types
SignUrlResponse
interface SignUrlResponse {
success: boolean;
message: string;
url?: string;
}UploadResponse
interface UploadResponse {
success: boolean;
message: string;
filename?: string;
driveid?: string;
}Notes
ZDrivemust be used server-side, as it requires yourdriveSecret.ZDriveClientmust be used in the browser, using signed URLs generated byZDrive.- Ensure your backend never exposes
driveSecretto clients.
AI Agent Skills
If you are using an AI agent, you can add ziqx-drive-js related skills to your agent using the following command:
npx skills add ziqx/ziqx-ai-skillsLicense
MIT © ZIQX
