Creating a fully featured cloud storage website with those specifications is a large-scale project. I'll provide you with a simplified but functional prototype using modern Web technologies. This prototype will:
jsx Copy code
/**
* A simple in-browser cloud storage prototype.
* Uses IndexedDB for file + metadata storage and persistence.
* Allows categories, file selection, downloads, and ZIP export.
*/
import React, { useState, useEffect, useRef } from "react";
import { openDB } from "idb";
import JSZip from "jszip";
const DB_NAME = "CloudStorage";
const DB_VERSION = 1;
const STORE_FILES = "files";
const STORE_CATEGORIES = "categories";
async function initDB() {
return openDB(DB_NAME, DB_VERSION, {
upgrade(db) {
if (!db.objectStoreNames.contains(STORE_FILES)) {
const store = db.createObjectStore(STORE_FILES, { keyPath: "id" });
store.createIndex("category", "category");
}
if (!db.objectStoreNames.contains(STORE_CATEGORIES)) {
db.createObjectStore(STORE_CATEGORIES, { keyPath: "id" });
}
},
});
}
function generateId() {
return Math.random().toString(36).substr(2, 9);
}
export default function CloudStorage() {
const [db, setDb] = useState(null);
const [categories, setCategories] = useState([]);
const [files, setFiles] = useState([]);
const [selectedCategory, setSelectedCategory] = useState("all");
const [selectedFiles, setSelectedFiles] = useState(new Set());
const categoryInputRef = useRef();
const fileInputRef = useRef();
// Initialize DB on mount
useEffect(() => {
initDB().then((database) => {
setDb(database);
});
}, []);
// Load categories & files when db changes or selectedCategory changes
useEffect(() => {
if (!db) return;
async function loadCategories() {
let allCategories = await db.getAll(STORE_CATEGORIES);
if (allCategories.length === 0) {
// Initialize with an 'Uncategorized' category
const defaultCat = { id: "uncategorized", name: "Uncategorized" };
await db.put(STORE_CATEGORIES, defaultCat);
allCategories = [defaultCat];
}
setCategories(allCategories);
}
async function loadFiles() {
let loadedFiles;
if (selectedCategory === "all") {
loadedFiles = await db.getAll(STORE_FILES);
} else if (selectedCategory === "uncategorized") {
// Files with category uncategorized or no category
let all = await db.getAll(STORE_FILES);
loadedFiles = all.filter(
(file) => !file.category || file.category === "uncategorized"
);
} else {
// Filter by category index
loadedFiles = await db.getAllFromIndex(STORE_FILES, "category", selectedCategory);
}
setFiles(loadedFiles);
setSelectedFiles(new Set());
}
loadCategories();
loadFiles();
}, [db, selectedCategory]);
// Add new category
const addCategory = async () => {
const name = categoryInputRef.current.value.trim();
if (!name) return alert("Category name cannot be empty");
if (categories.find((c) => c.name.toLowerCase() === name.toLowerCase())) {
return alert("Category already exists");
}
const newCat = { id: generateId(), name };
await db.put(STORE_CATEGORIES, newCat);
categoryInputRef.current.value = "";
setCategories([...categories, newCat]);
};
// Upload files handler
const onFilesSelected = async (e) => {
const filesSelected = Array.from(e.target.files);
const oversized = filesSelected.filter(file => file.size > 10 * 1024**3);
if (oversized.length) {
alert(`Some files exceed 10GB limit and won't be uploaded:\n${oversized.map(f => f.name).join("\n")}`);
return;
}
for (const file of filesSelected) {
const id = generateId();
// Save file as blob plus metadata
try {
await db.put(STORE_FILES, {
id,
name: file.name,
blob: file, // store actual file blob
size: file.size,
type: file.type,
category: "uncategorized",
created: Date.now(),
});
} catch (err) {
alert("Error storing file: " + err.message);
}
}
// Refresh file list
const loadedFiles = await db.getAll(STORE_FILES);
setFiles(loadedFiles);
e.target.value = null; // clear input
};
// Change file category
const changeFileCategory = async (fileId, newCatId) => {
const file = await db.get(STORE_FILES, fileId);
if (!file) return;
file.category = newCatId;
await db.put(STORE_FILES, file);
// Refresh files
if (selectedCategory === "all" || selectedCategory === newCatId || selectedCategory === file.category) {
const loadedFiles = await db.getAll(STORE_FILES);
setFiles(loadedFiles);
}
};
// Download single file
const downloadFile = (file) => {
const url = URL.createObjectURL(file.blob);
const a = document.createElement("a");
a.href = url;
a.download = file.name;
a.click();
URL.revokeObjectURL(url);
};
// Toggle file selection
const toggleSelectFile = (fileId) => {
const newSet = new Set(selectedFiles);
if (newSet.has(fileId)) {
newSet.delete(fileId);
} else {
newSet.add(fileId);
}
setSelectedFiles(newSet);
};
// Download selected as ZIP
const downloadZip = async () => {
if (selectedFiles.size === 0) return alert("No files selected for ZIP download");
const zip = new JSZip();
for (const fileId of selectedFiles) {
const file = await db.get(STORE_FILES, fileId);
if (file) {
zip.file(file.name, file.blob);
}
}
const content = await zip.generateAsync({ type: "blob" });
const url = URL.createObjectURL(content);
const a = document.createElement("a");
a.href = url;
a.download = "files.zip";
a.click();
URL.revokeObjectURL(url);
};
// Delete file
const deleteFile = async (fileId) => {
if (!window.confirm("Delete this file?")) return;
await db.delete(STORE_FILES, fileId);
const loadedFiles = await db.getAll(STORE_FILES);
setFiles(loadedFiles);
setSelectedFiles((prev) => {
const newSet = new Set(prev);
newSet.delete(fileId);
return newSet;
});
};
return (
<div style={{ maxWidth: 900, margin: "auto", fontFamily: "Arial, sans-serif" }}>
<h1>Free Cloud Storage Prototype (Local Browser)</h1>
<h3>Categories:</h3>
<div style={{ display: "flex", alignItems: "center", gap: 10, flexWrap: "wrap" }}>
<button
onClick={() => setSelectedCategory("all")}
style={{
backgroundColor: selectedCategory === "all" ? "#0b79f7" : "#eee",
color: selectedCategory === "all" ? "#fff" : "#000",
border: "none",
borderRadius: 5,
padding: "5px 10px",
cursor: "pointer",
}}
>
All
</button>
{categories.map((cat) => (
<button
key={cat.id}
onClick={() => setSelectedCategory(cat.id)}
style={{
backgroundColor: selectedCategory === cat.id ? "#0b79f7" : "#eee",
color: selectedCategory === cat.id ? "#fff" : "#000",
border: "none",
borderRadius: 5,
padding: "5px 10px",
cursor: "pointer",
}}
>
{cat.name}
</button>
))}
<input
type="text"
placeholder="New Category"
ref={categoryInputRef}
style={{ flexGrow: 1, minWidth: 130, padding: 5, borderRadius: 5, border: "1px solid #ccc" }}
/>
<button onClick={addCategory} style={{ padding: "6px 12px" }}>
Add
</button>
</div>
<hr />
<h3>Upload Files (Max 10GB each):</h3>
<input
type="file"
multiple
onChange={onFilesSelected}
ref={fileInputRef}
style={{ marginBottom: 20 }}
/>
<h3>
Files in "
{selectedCategory === "all"
? "All"
: categories.find((cat) => cat.id === selectedCategory)?.name || selectedCategory}
" ({files.length})
</h3>
{files.length === 0 && <p>No files in this category.</p>}
{files.length > 0 && (
<>
<table
style={{
width: "100%",
borderCollapse: "collapse",
marginBottom: 10,
fontSize: 14,
}}
>
<thead>
<tr>
<th style={{ border: "1px solid #ddd", padding: 8 }}>Select</th>
<th style={{ border: "1px solid #ddd", padding: 8 }}>File Name</th>
<th style={{ border: "1px solid #ddd", padding: 8, width: 150 }}>
Category
</th>
<th style={{ border: "1px solid #ddd", padding: 8, width: 120 }}>
Size
</th>
<th style={{ border: "1px solid #ddd", padding: 8, width: 180 }}>
Actions
</th>
</tr>
</thead>
<tbody>
{files.map((file) => (
<tr key={file.id}>
<td
style={{
border: "1px solid #ddd",
padding: 8,
textAlign: "center",
}}
>
<input
type="checkbox"
checked={selectedFiles.has(file.id)}
onChange={() => toggleSelectFile(file.id)}
/>
</td>
<td style={{ border: "1px solid #ddd", padding: 8 }}>
{file.name}
</td>
<td style={{ border: "1px solid #ddd", padding: 8, textAlign: "center" }}>
<select
value={file.category || "uncategorized"}
onChange={(e) => changeFileCategory(file.id, e.target.value)}
>
{categories.map((cat) => (
<option key={cat.id} value={cat.id}>
{cat.name}
</option>
))}
{!categories.find((c) => c.id === "uncategorized") && (
<option value="uncategorized">Uncategorized</option>
)}
</select>
</td>
<td style={{ border: "1px solid #ddd", padding: 8, textAlign: "right" }}>
{(file.size / (1024 * 1024)).toFixed(2)} MB
</td>
<td style={{ border: "1px solid #ddd", padding: 8, textAlign: "center" }}>
<button onClick={() => downloadFile(file)} style={{ marginRight: 6 }}>
Download
</button>
<button onClick={() => deleteFile(file.id)} style={{ color: "red" }}>
Delete
</button>
</td>
</tr>
))}
</tbody>
</table>
<button
onClick={downloadZip}
disabled={selectedFiles.size === 0}
style={{
padding: "8px 16px",
backgroundColor: selectedFiles.size === 0 ? "#ccc" : "#0b79f7",
color: "#fff",
border: "none",
borderRadius: 5,
cursor: selectedFiles.size === 0 ? "default" : "pointer",
}}
>
Download Selected as ZIP ({selectedFiles.size})
</button>
</>
)}
<hr />
<p style={{ fontSize: 12, color: "#555" }}>
Note: This is a purely client-side demo storing files locally using your
browser's storage (IndexedDB). Files will persist on this device/browser,
but will not sync on other devices. Maximum file size per upload is 10GB
(limited by browser). Total storage size limited by your browser and
available device storage.
</p>
</div>
);
}
If you want, I can also help you build a backend solution or a skeleton API for real cloud storage.