1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const jsonData = await (await fetch("https://tempdev-brilliantbronzevicuna.web.val.run/")).text();
// Create a FormData object
const formData = new FormData();
// Create a Blob from the JSON data
const blob = new Blob([jsonData], { type: "application/javascript" });
// Append the Blob to the FormData object
formData.append("file", blob, "data.ts");
// URL of your API
const apiUrl = "https://filehaus.top/api/upload/data.ts"; // Replace with your API URL
// Send the file using fetch
try {
const response = await fetch(apiUrl, {
method: "POST",
body: formData,
headers: {
// Include headers if necessary
// 'X-Torrent': '1', // Optional header
// "X-Expires-After": "0", // Optional header, replace with your expiry value
},
});
const result = await response.text();
console.log(response.headers);
console.log("Response:", result);
} catch (error) {
console.error("Error:", error.message);
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
August 10, 2024