login-template/web/uploadimage.html

43 lines
1.1 KiB
HTML
Raw Permalink Normal View History

2024-03-01 14:02:37 -08:00
<!DOCTYPE html>
<html lang="en">
<head>
<title>image test</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/style.css" rel="stylesheet">
</head>
<body>
<form id="image-form">
<input type="file" name="file" accept="image/png">
<input type="submit" name="submit" value="submit">
</form>
</body>
<script defer>
document.getElementById("image-form").addEventListener("submit", async (event) => {
event.preventDefault();
// this doesn't work
// const file = event.target.files[0];
// console.log(file)
var input = document.querySelector('input[type="file"]')
console.log(input.files[0])
const token = await fetch("http://127.0.0.1:8000/upload", {
method: "POST",
header: {
"Content-Type": "image/png",
"Access-Control-Allow-Origin": "http://127.0.0.1:8000/upload"
},
body: input.files[0]
})
2024-03-22 12:10:51 -07:00
// TODO: if status is 200, not 201, alert the user to tell the admins to clear tmpimages
2024-03-01 14:02:37 -08:00
alert(await token.text());
});
</script>
</html>