@uploadfast/client
v1.1.0
Published
Javascript SDK for UploadFast
Downloads
23
Maintainers
Readme
UploadFast JS SDK
A lightweight JavaScript SDK for seamlessly uploading and managing files with UploadFast.
UploadFast is a media management platform that leverages cloudflare's global edge network to serve your users images and videos (fast)!
This SDK provides a simple interface for handling file uploads, deletions, and management in your web applications.
Installation
Install using your preferred package manager:
npm install @uploadfast/client
# or
yarn add @uploadfast/client
# or
pnpm add @uploadfast/clientQuick Start
import { createClient } from "@uploadfast/client";
// Initialize the client
const uploadfast = createClient({
apiKey: "your_api_key_here",
});
// Upload a single file
const file = new File(["file content"], "example.png", { type: "image/png" });
try {
const response = await uploadfast.upload({ resource: file });
console.log("Upload successful:", response[0].url);
} catch (error) {
console.error("Upload failed:", error);
}API Reference
Initialization
Create a new UploadFast client instance:
import { createClient } from "@uploadfast/client";
const uploadfast = createClient({
apiKey: process.env.UPLOAD_FAST_API_KEY,
});File Upload
Upload a single file or multiple files:
// Single file upload
const file = new File(["content"], "example.png", { type: "image/png" });
const response = await uploadfast.upload({
resource: file,
});
// response type: { file_name: string; file_size: number; url: string; bucket: string; }[]
// Multiple files upload
const files = [
new File(["content1"], "example1.png", { type: "image/png" }),
new File(["content2"], "example2.jpg", { type: "image/jpeg" }),
];
const response = await uploadfast.upload({
resource: files,
});