Skip to content

Instantly share code, notes, and snippets.

@b1naryth1ef
Last active May 14, 2024 07:54
Show Gist options
  • Save b1naryth1ef/4b649811c903e6c26283110167620cb4 to your computer and use it in GitHub Desktop.
Save b1naryth1ef/4b649811c903e6c26283110167620cb4 to your computer and use it in GitHub Desktop.
export async function upload(name: string, data: any) {
const { getSecret } = await import("@maf/core.ts");
// import { getSecret } from "@maf/core.ts";
const token = await getSecret("FILES_TOKEN");
if (!token) {
console.warn("no files upload token provided, skipping");
return;
}
const formData = new FormData();
formData.append("file", new Blob([data.buffer]), name);
const res = await fetch("https://files.hydr0.com/volume/infra-files/upload", {
method: "POST",
body: formData,
headers: [["Authorization", `APIKey ${token}`]],
});
if (!res.ok) {
throw new Error(`failed to upload file: ${await res.text()}`);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment