
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
sdk-imagebb
Advanced tools
Modern, lightweight TypeScript library for uploading images to ImgBB API. Features React 19 & Node 24 support, promise-based async/await interface, automatic error handling, and configurable expiration. Perfect for building image upload functionality in R
Modern, lightweight TypeScript library for uploading images to ImgBB API with full React 18 & 19 support
⚠️ Disclaimer: This is an unofficial SDK for ImgBB. This project is not affiliated with, endorsed by, or sponsored by ImgBB. It is an independent, community-maintained library built for educational and practical purposes.
A powerful and easy-to-use image uploader for ImgBB with zero dependencies. Perfect for React applications, vanilla JavaScript, and TypeScript projects. Features promise-based async/await interface, automatic error handling, and configurable expiration settings.
npm install sdk-imagebb
yarn add sdk-imagebb
pnpm add sdk-imagebb
# Using npm/pnpm/yarn
npx jsr add @supratimrk/sdk-imagebb
# Using Deno
deno add @supratimrk/sdk-imagebb
# Using import maps
{
"imports": {
"@supratimrk/sdk-imagebb": "jsr:@supratimrk/sdk-imagebb@^1.0.2"
}
}
This package is published to both npm and JSR registries:
npm install sdk-imagebbnpx jsr add @supratimrk/sdk-imagebb or deno add @supratimrk/sdk-imagebb⚠️ Security Warning: Never expose your ImgBB API key in frontend/client-side code. API keys should be kept secret and only used in server-side environments. For web applications, implement image uploads through your backend API to prevent key exposure.
import { imgbbUpload } from "sdk-imagebb";
// Simple upload
const uploadImage = async (file: File) => {
try {
const response = await imgbbUpload({
key: "your-api-key",
image: file,
});
console.log("Image URL:", response.data.url);
console.log("Display URL:", response.data.display_url);
console.log("Delete URL:", response.data.delete_url);
} catch (error) {
console.error("Upload failed:", error);
}
};
import React, { useState } from "react";
import { imgbbUpload } from "sdk-imagebb";
const ImageUploader: React.FC = () => {
const [imageUrl, setImageUrl] = useState<string>("");
const [uploading, setUploading] = useState(false);
const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0];
if (!file) return;
setUploading(true);
try {
const response = await imgbbUpload({
key: process.env.IMGBB_API_KEY!,
image: file,
name: file.name,
});
setImageUrl(response.data.display_url);
} catch (error) {
console.error("Upload failed:", error);
} finally {
setUploading(false);
}
};
return (
<div>
<input
type="file"
accept="image/*"
onChange={handleFileChange}
disabled={uploading}
/>
{uploading && <p>Uploading...</p>}
{imageUrl && <img src={imageUrl} alt="Uploaded" />}
</div>
);
};
export default ImageUploader;
Note: This React example assumes you're using a framework like Next.js where
process.envvariables are securely handled on the server-side. For client-side only React applications, implement the upload logic in your backend API to keep the API key secure.
import { imgbbUpload } from "sdk-imagebb";
import { readFileSync } from "fs";
import { resolve } from "path";
const uploadImageFromFile = async (filePath: string) => {
try {
// Read the image file from disk
const imageBuffer = readFileSync(resolve(filePath));
// Create a File-like object for Node.js (requires Node.js 20+)
const file = new File([imageBuffer], "image.jpg", { type: "image/jpeg" });
const response = await imgbbUpload({
key: process.env.IMGBB_API_KEY!,
image: file,
name: "node-upload-example",
expiration: 3600, // 1 hour
});
console.log("Upload successful!");
console.log("Image URL:", response.data.url);
console.log("Display URL:", response.data.display_url);
console.log("Delete URL:", response.data.delete_url);
return response.data;
} catch (error) {
console.error("Upload failed:", error);
throw error;
}
};
// Usage
uploadImageFromFile("./path/to/your/image.jpg")
.then((data) => console.log("Image uploaded:", data.url))
.catch((error) => console.error("Error:", error));
Note: The
FileAPI is available in Node.js 20+. For Node.js 18, you'll need to use a polyfill or alternative approach for creating File objects.
import { imgbbUpload } from "@supratimrk/sdk-imagebb";
// Read the image file from disk
const imageBuffer = await Deno.readFile("./path/to/your/image.jpg");
// Create a File-like object for Deno
const file = new File([imageBuffer], "image.jpg", { type: "image/jpeg" });
const response = await imgbbUpload({
key: Deno.env.get("IMGBB_API_KEY")!,
image: file,
name: "deno-upload-example",
expiration: 3600, // 1 hour
});
console.log("Upload successful!");
console.log("Image URL:", response.data.url);
import { imgbbUpload } from "sdk-imagebb";
// HTML: <input type="file" id="fileInput" accept="image/*">
const fileInput = document.getElementById('fileInput');
fileInput.addEventListener('change', async (event) => {
const file = event.target.files[0];
if (!file) return;
try {
const response = await imgbbUpload({
key: 'your-api-key', // Never expose in production! Use backend instead
image: file,
name: file.name,
});
console.log('Upload successful!');
console.log('Image URL:', response.data.url);
// Display the uploaded image
const img = document.createElement('img');
img.src = response.data.display_url;
document.body.appendChild(img);
} catch (error) {
console.error('Upload failed:', error.message);
alert('Failed to upload image');
}
});
import { imgbbUpload } from "sdk-imagebb";
const uploadWithOptions = async (file: File) => {
const response = await imgbbUpload({
key: "your-api-key",
image: file,
name: "custom-image-name", // Optional: Custom name for the image
expiration: 600, // Optional: Auto-delete after 600 seconds (10 minutes)
});
return response;
};
sdk-imagebb supports all major image formats accepted by ImgBB:
.jpg, .jpeg.png.gif (including animated).bmp.webp| Limit Type | Value | Description |
|---|---|---|
| Max File Size | 32 MB | Maximum image file size (free tier) |
| Min Expiration | 60 seconds | Minimum auto-deletion time |
| Max Expiration | 15,552,000 seconds | Maximum auto-deletion time (~180 days) |
| Default Expiration | None | Images are permanent unless specified |
Note: File size limits may vary based on your ImgBB account type. Free accounts support up to 32MB per image.
ImgBB enforces rate limits to ensure fair usage:
Tip: If you hit rate limits, consider implementing a queue system for batch uploads or upgrading your ImgBB account.
imgbbUpload(options: ImgbbUploadOptions): Promise<Root>| Parameter | Type | Required | Description |
|---|---|---|---|
key | string | Yes | Your ImgBB API key |
image | File | Yes | The image file to upload (from file input) |
name | string | No | Custom name for the uploaded image |
expiration | number | No | Auto-deletion time in seconds (e.g., 600 for 10 minutes) |
interface Root {
data: {
id: string;
title: string;
url_viewer: string;
url: string;
display_url: string;
width: string;
height: string;
size: string;
time: string;
expiration: string;
image: {
filename: string;
name: string;
mime: string;
extension: string;
url: string;
};
thumb: {
filename: string;
name: string;
mime: string;
extension: string;
url: string;
};
medium: {
filename: string;
name: string;
mime: string;
extension: string;
url: string;
};
delete_url: string;
};
success: boolean;
status: number;
}
{
"data": {
"id": "2ndCYJK",
"title": "c1f64245afb2",
"url_viewer": "https://ibb.co/2ndCYJK",
"url": "https://i.ibb.co/w04Prt6/c1f64245afb2.gif",
"display_url": "https://i.ibb.co/98W13PY/c1f64245afb2.gif",
"width": "1920",
"height": "1080",
"size": "42",
"time": "1552042565",
"expiration": "600",
"image": {
"filename": "c1f64245afb2.gif",
"name": "c1f64245afb2",
"mime": "image/gif",
"extension": "gif",
"url": "https://i.ibb.co/w04Prt6/c1f64245afb2.gif"
},
"thumb": {
"filename": "c1f64245afb2.gif",
"name": "c1f64245afb2",
"mime": "image/gif",
"extension": "gif",
"url": "https://i.ibb.co/2ndCYJK/c1f64245afb2.gif"
},
"medium": {
"filename": "c1f64245afb2.gif",
"name": "c1f64245afb2",
"mime": "image/gif",
"extension": "gif",
"url": "https://i.ibb.co/98W13PY/c1f64245afb2.gif"
},
"delete_url": "https://ibb.co/2ndCYJK/670a7e48ddcb85ac340c717a41047e5c"
},
"success": true,
"status": 200
}
The library includes comprehensive error handling with descriptive error messages to help you debug issues quickly.
// Error: ImgBB API key is required and must be a non-empty string
await imgbbUpload({ key: "", image: file });
// Error: Invalid image type: application/pdf. Supported types: JPEG, PNG, GIF, BMP, WEBP
await imgbbUpload({ key: "your-key", image: pdfFile });
// Error: Expiration must be a number between 60 and 15552000 seconds
await imgbbUpload({ key: "your-key", image: file, expiration: 30 });
// Error: Upload timed out after 30 seconds
// Occurs when network is slow or file is too large
// Error: ImgBB API error: HTTP 403: Forbidden
// Check your API key or account status
import { imgbbUpload } from "sdk-imagebb";
const uploadWithErrorHandling = async (file: File) => {
try {
const response = await imgbbUpload({
key: process.env.IMGBB_API_KEY!,
image: file,
});
return { success: true, data: response.data };
} catch (error) {
if (error instanceof Error) {
// Log specific error for debugging
console.error("Upload failed:", error.message);
// Return user-friendly message
if (error.message.includes("timeout")) {
return { success: false, error: "Upload is taking too long. Please try again." };
} else if (error.message.includes("Invalid image type")) {
return { success: false, error: "Please select a valid image file." };
} else if (error.message.includes("API key")) {
return { success: false, error: "Configuration error. Please contact support." };
}
}
return { success: false, error: "An unexpected error occurred." };
}
};
sdk-imagebb works in all modern browsers that support:
| Browser | Minimum Version |
|---|---|
| Chrome | 76+ |
| Firefox | 69+ |
| Safari | 12.1+ |
| Edge | 79+ |
| Opera | 63+ |
Required Browser APIs:
FormData APIFetch APIFile APIAbortController (for timeout handling)Note: Internet Explorer is not supported. For legacy browser support, consider using polyfills for Fetch and AbortController.
Contributions, issues, and feature requests are welcome!
git checkout -b feature/AmazingFeature)git commit -m 'Add some AmazingFeature')git push origin feature/AmazingFeature)See CONTRIBUTING.md for more details.
Problem: API key is missing or empty.
Solution: Ensure you're passing a valid API key from your ImgBB account.
// ❌ Wrong
await imgbbUpload({ key: "", image: file });
// ✅ Correct
await imgbbUpload({ key: "your-valid-api-key", image: file });
Problem: Network is slow or file is too large.
Solution:
Problem: File format is not supported.
Solution: Only use JPEG, PNG, GIF, BMP, or WEBP formats.
// Check file type before uploading
const validTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/bmp', 'image/webp'];
if (!validTypes.includes(file.type)) {
console.error('Unsupported file type');
}
Problem: Invalid API key or account issue.
Solution:
Problem: CORS errors when uploading from frontend.
Solution: ImgBB API supports CORS, but for security, implement uploads through your backend:
// Frontend - send file to your backend
const formData = new FormData();
formData.append('image', file);
const response = await fetch('/api/upload', {
method: 'POST',
body: formData
});
// Backend - handle upload to ImgBB
// (keeps API key secure)
Problem: Invalid expiration value.
Solution: Use a value between 60 seconds (1 minute) and 15,552,000 seconds (180 days).
// ❌ Wrong
await imgbbUpload({ key: "key", image: file, expiration: 30 });
// ✅ Correct
await imgbbUpload({ key: "key", image: file, expiration: 3600 }); // 1 hour
Problem: Silent failure or network issue.
Solution:
If you encounter problems not listed here:
This project is MIT licensed.
Supratim Mondal
This is an unofficial SDK and is not affiliated with, endorsed by, or sponsored by ImgBB. This project is maintained independently for educational and practical purposes. Use of ImgBB's services is subject to their terms of service.
Give a ⭐ if this project helped you!
Keywords: imgbb, imgbb-api, sdk-imagebb, image-upload, image-hosting, react, react-18, react-19, typescript, file-upload, cdn, image-cdn, cloud-storage, browser-upload, imgbb-client, unofficial-sdk
FAQs
Modern, lightweight TypeScript library for uploading images to ImgBB API. Features React 19 & Node 24 support, promise-based async/await interface, automatic error handling, and configurable expiration. Perfect for building image upload functionality in R
We found that sdk-imagebb demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.