Last active
May 14, 2024 07:54
-
-
Save b1naryth1ef/4b649811c903e6c26283110167620cb4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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