43 lines
1.1 KiB
HTML
43 lines
1.1 KiB
HTML
<!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]
|
|
})
|
|
|
|
// TODO: if status is 200, not 201, alert the user to tell the admins to clear tmpimages
|
|
alert(await token.text());
|
|
});
|
|
|
|
</script>
|
|
|
|
</html>
|