import { readFile } from "node:fs/promises";
const apiKey = process.env.OPENINARY_API_KEY;
if (!apiKey) throw new Error("Missing OPENINARY_API_KEY");
async function uploadVideo() {
const bytes = await readFile("./video.mp4");
const file = new File([bytes], "video.mp4", { type: "video/mp4" });
const form = new FormData();
form.append("files", file);
form.append(
"transformations",
JSON.stringify([
"w_1280,h_720,q_75,f_mp4",
"t_true,tt_3,w_320,h_180,f_webp,q_70",
]),
);
const res = await fetch("http://localhost:3000/upload", {
method: "POST",
headers: { Authorization: `Bearer ${apiKey}` },
body: form,
});
if (!res.ok) {
throw new Error(`Upload failed: ${res.status} ${await res.text()}`);
}
const data = await res.json();
console.log(data);
}
uploadVideo().catch(console.error);