Public
Script
Readme

upload to 0x0.st

usage:

import { uploadTo0x0 } from "https://esm.town/v/easrng/uploadTo0x0" console.log(await uploadTo0x0("test data", "filename"))

data can be a string, a TypedArray, an ArrayBuffer, or a Blob
returns a url (ie https://0x0.st/X-wB.txt) to a file that expires after an hour

1
2
3
4
5
6
7
8
9
10
11
export async function uploadTo0x0(data, name) {
const blob = new Blob([data]);
const formData = new FormData();
formData.append("file", blob, name);
formData.append("expires", "1");
const response = await fetch("https://0x0.st", {
method: "POST",
body: formData,
});
return await response.text();
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
v12 was merged from the PR "modernize" by stevekrouse
Comments
Nobody has commented on this val yet: be the first!
April 19, 2024