Uploader JavaScript SDK

Upload files and shorten URLs from Node and TypeScript with the hepgg package, using native multipart with no extra dependencies.

Uploader SDK

The hepgg package wraps the Uploader in a typed client. Hand it a Buffer, Blob, or Uint8Array and it builds the multipart request for you with native FormData. It also shortens URLs through the same endpoint.

Install

flag
npm install hepgg --registry https://npm.hep.gg

Upload A File

import { Uploader } from "hepgg/uploader";
import { readFile } from "node:fs/promises";
 
const up = new Uploader({ token: process.env.HYD_UP_KEY });
 
const png = await readFile("cat.png");
const { url } = await up.upload(png, { filename: "cat.png", contentType: "image/png" });
 
console.log(url); // https://i.hep.gg/abc123.png

upload() accepts a Buffer, Uint8Array, Blob, File, or ArrayBuffer. The filename drives the stored extension.

Shorten A URL

Send a link to the same endpoint and get a short URL back.

const { url } = await up.shorten("https://example.com/very/long/path");
console.log(url); // https://i.hep.gg/aB3dE

Options And Errors

new Uploader(options)
token
stringrequired
Your hyd-up- token.
baseURL
stringoptionaldefault: https://hep.gg
Upload host.
serveHost
stringoptionaldefault: https://i.hep.gg
Used by urlFor(id) to build a serve URL.
authScheme
raw | beareroptionaldefault: raw
How the token is sent. The upload route expects the raw header; switch to bearer only if your account requires it.
timeoutMs
numberoptionaldefault: 10000
Per-request timeout.
retries
numberoptionaldefault: 2
Safe retries. An upload is never replayed after a server response.
import { HepError } from "hepgg";
 
try {
  await up.upload(buf, { filename: "big.zip" });
} catch (err) {
  if (err instanceof HepError && err.status === 403) console.error("too large or access not enabled");
}

Full Reference

Uploading, URL shortener, and Serving and embeds.