Comment on page

Uploading image to Imgur with Bunjs

imgur, bunjs, code, image-upload
  • No need external dependency except bun-types
export async function uploadToImgur(imageData: ArrayBuffer): Promise<string> {
const response = await fetch("", {
method: "POST",
body: imageData,
headers: {
Authorization: "Client-ID dd32dd3c6aaa9a0",
"Content-Type": "application/octet-stream"
if (!response.ok) throw new Error(`Failed to upload image: ${response.statusText}`)
const responseData = await response.json()
export async function uploadFromPath(imagePath: string): Promise<string> {
const imageFile = Bun.file(imagePath)
const imageBytes = await imageFile.arrayBuffer()
return await uploadToImgur(imageBytes)
2023 © Yunus Emre AK