persistent-image-url
Version:
A lightweight Node.js library for persisting image URLs using the [imgbb.com](https://imgbb.com/) or [sm.ms](https://sm.ms/) API. This library allows you to upload images from temporary URLs and get back persistent URLs that can be used to access the imag
24 lines (19 loc) • 517 B
text/typescript
import axios from "axios";
const IMGBB_URL = "https://api.imgbb.com/1/upload";
export async function uploadImageToImgbb(
imageBase64: string,
token: string
): Promise<string> {
try {
const formData = new FormData();
formData.append("image", imageBase64);
const res = await axios.post(IMGBB_URL, formData, {
params: {
key: token,
},
});
return res.data.data.url;
} catch (error) {
throw new Error("Unable to upload image to Imgbb");
}
}