64 lines
1.8 KiB
HTML
64 lines
1.8 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Document</title>
|
|
|
|
<style>
|
|
body {
|
|
background-color: black;
|
|
color: white;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<label>Select image to upload</label>
|
|
<input type="file" name="myFile" id="fileinput">
|
|
|
|
<br><br>
|
|
<span id="res-url">Upload file to see url</span>
|
|
<button id="btn-open">Open in new tab</button>
|
|
|
|
<script>
|
|
//const url = "http://localhost:8081/v1/user/avatar"
|
|
const url = "https://alpha-storage.clickandjoin.umbach.dev/v1/user/avatar"
|
|
|
|
const input = document.getElementById("fileinput")
|
|
|
|
const upload = (file) => {
|
|
const data = new FormData()
|
|
data.append("file", file)
|
|
|
|
fetch(url,{
|
|
method: "POST",
|
|
headers: {
|
|
"X-Authorization": "SpebbxEG-gOTn-C7z6-SvO3-UCtv9ZRleg3r"
|
|
},
|
|
body: data
|
|
})
|
|
.then(res => res.text())
|
|
.then(succ => {
|
|
console.log(succ)
|
|
|
|
let json = JSON.parse(succ)
|
|
|
|
document.getElementById("res-url").innerHTML = json["AvatarUrl"]
|
|
|
|
window.open(document.getElementById("res-url").innerHTML, "_blank")
|
|
|
|
})
|
|
.catch(err => console.log(err))
|
|
}
|
|
|
|
const onSelectFile = () => upload(input.files[0])
|
|
|
|
input.addEventListener("change", onSelectFile, false)
|
|
|
|
document.getElementById("btn-open").onclick = () => {
|
|
window.open(document.getElementById("res-url").innerHTML, "_blank")
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |