cloudprime
v1.1.1
Published
A versatile JavaScript Package for seamless file uploads and management using the CloudPrime, supporting images, videos, documents, presentations, spreadsheets, and all file types. Compatible with modern web and backend frameworks.
Maintainers
Readme
CloudPrime Documentation
The CloudPrime is a versatile JavaScript package designed for seamless file uploads and management. It integrates effortlessly with modern web and backend frameworks, providing a secure and reliable solution for handling images, videos, documents, presentations, spreadsheets, and all file types.
Features
- Universal File Support: Upload images (JPG, PNG, GIF, WEBP), videos (MP4, MOV, AVI), documents (PDF, DOC, PPT), spreadsheets (CSV, XLSX), and any file format.
- Secure File Uploads: Upload files with API key authentication to ensure data security.
- Effortless Integration: Works seamlessly with React, Vue, Angular, Node.js, Express, and other frameworks.
- File Retrieval: Retrieve uploaded files via simple API calls.
- API Usage Tracking: Monitor your usage statistics and limits in real-time.
Getting Started
Step 1: Register and Obtain an API Key
- Visit the CloudPrime Platform to create your account.
- After registering, log in to your account and navigate to the Dashboard.
- Go to the API Keys section and generate your unique API key.
- This API key will be required for all API interactions.
Step 2: Access the Documentation
Refer to the CloudPrime Documentation for detailed information on available endpoints, request formats, and example responses.
Installation
To use the CloudPrime in your JavaScript application, install the package using npm:
npm install cloudprimeUsage Examples
Browser/React/Vue/Angular Example
import CloudPrime from 'cloudprime';
// Replace with your actual API key from CloudPrime dashboard
const API_KEY = "your_actual_api_key_here";
// Initialize the CloudPrime client
const cloudPrime = new CloudPrime(API_KEY);
// Get API usage statistics
async function getStats() {
try {
const stats = await cloudPrime.getUploadInfo();
console.log("API Usage Stats:", stats);
} catch (error) {
console.error("Error fetching stats:", error);
}
}
// Upload a file from file input
async function uploadFile(fileInput) {
const file = fileInput.files[0];
if (!file) {
alert("Please select a file first!");
return;
}
try {
console.log(`Uploading ${file.name}...`);
const result = await cloudPrime.uploadFile(file);
console.log("Upload successful!");
console.log("File URL:", result.data.publicUrl);
console.log("File ID:", result.data.id);
console.log("File Size:", result.data.fileSize);
return result;
} catch (error) {
console.error("Upload failed:", error);
throw error;
}
}
// Call functions
getStats();
// Example: Trigger upload on file input change
document.getElementById('fileInput').addEventListener('change', async (e) => {
await uploadFile(e.target);
});Node.js Example
const CloudPrime = require('cloudprime');
const fs = require('fs').promises;
// Note: For Node.js, you'll need to handle file differently
// This example shows the concept
const API_KEY = "your_actual_api_key_here";
const cloudPrime = new CloudPrime(API_KEY);
async function nodeExample() {
try {
// Get usage stats
const stats = await cloudPrime.getUploadInfo();
console.log("API Usage Stats:", stats);
// In Node.js, you would need to convert file to FormData
// or use a different approach for file upload
console.log("Node.js usage requires additional file handling");
} catch (error) {
console.error("Error:", error);
}
}
nodeExample();Example Response
API Usage Statistics Response:
{
"success": true,
"data": {
"keyName": "Development Key",
"isActive": true,
"lastUsed": "2026-01-05T15:29:07.817Z",
"usageCount": 42,
"totalUploads": 25,
"uploadsThisMonth": 15,
"uploadLimit": "1000",
"usagePercentage": 4.2,
"createdAt": "2026-01-01T10:00:00.000Z",
"expiresAt": "2027-01-01T10:00:00.000Z"
}
}File Upload Success Response:
{
"success": true,
"data": {
"id": "695bd8c4f91c7ee047d11bf8",
"publicUrl": "https://imageserve.pythonanywhere.com/media/uploads/your_uploaded_image.jpg",
"fileSize": "1.74 MB",
"fileName": "profile-image.jpg",
"fileType": "image/jpeg",
"uploadedAt": "2026-01-05T15:30:45.123Z"
}
}Console Output Example:
API Usage Stats: {
success: true,
data: {
keyName: 'Development Key',
isActive: true,
lastUsed: '2026-01-05T15:29:07.817Z',
usageCount: 42,
totalUploads: 25,
uploadsThisMonth: 15,
uploadLimit: '1000',
usagePercentage: 4.2,
createdAt: '2026-01-01T10:00:00.000Z',
expiresAt: '2027-01-01T10:00:00.000Z'
}
}
Uploading presentation.pptx...
Upload successful!
File URL: https://imageserve.pythonanywhere.com/media/uploads/your_uploaded_image.pptx
File ID: 695bd8c4f91c7ee047d11bf8
File Size: 8.45 MBSupported File Types
- Images: .jpg, .jpeg, .png, .gif, .bmp, .webp, .svg, .tiff
- Videos: .mp4, .avi, .mov, .mkv, .wmv, .flv, .webm
- Documents: .pdf, .doc, .docx, .ppt, .pptx, .txt, .rtf
- Spreadsheets: .csv, .xls, .xlsx, .ods
- Archives: .zip, .rar, .7z, .tar.gz
- Code Files: .js, .ts, .html, .css, .json, .xml, .py
- Audio: .mp3, .wav, .ogg, .m4a
- And any other file type...
Framework Integration
React Example
import React, { useState } from 'react';
import CloudPrime from 'cloudprime';
function FileUploader() {
const [file, setFile] = useState(null);
const [result, setResult] = useState(null);
const API_KEY = "your_api_key_here";
const cloudPrime = new CloudPrime(API_KEY);
const handleFileChange = (e) => {
setFile(e.target.files[0]);
};
const handleUpload = async () => {
if (!file) return;
try {
const response = await cloudPrime.uploadFile(file);
setResult(response.data);
console.log('Upload successful:', response);
} catch (error) {
console.error('Upload failed:', error);
}
};
return (
<div>
<input type="file" onChange={handleFileChange} />
<button onClick={handleUpload}>Upload File</button>
{result && (
<div>
<p>File URL: <a href={result.publicUrl}>{result.publicUrl}</a></p>
<p>File Size: {result.fileSize}</p>
</div>
)}
</div>
);
}Key Points
- Keep your API key secure and never expose it in client-side code.
- Ensure that the API key is included in the request header (X-API-Key) for authentication.
- The package works in both browser and Node.js environments (with appropriate file handling).
- Files are uploaded securely and stored with unique, accessible URLs.
- Explore advanced features and additional endpoints in the CloudPrime Documentation.
Support
- For questions or support:
- Visit our Documentation
- Check Dashboard for API management
- Contact us at [email protected]
License
MIT License
Thank you for choosing CloudPrime for your file management needs!
