-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.html
48 lines (44 loc) · 1.44 KB
/
upload.html
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>dnd binary upload</title>
<script type="application/javascript">
function sendFile(file) {
const uri = "/upload";
const xhr = new XMLHttpRequest();
xhr.open("POST", uri, true);
xhr.onreadystatechange = () => {
if (xhr.readyState === 4 && xhr.status === 200) {
alert(xhr.responseText); // handle response.
}
};
var blob = new Blob([file], {type: 'image/jpeg'});
xhr.send(blob);
}
window.onload = () => {
var form = document.forms.myform;
form.elements.button.onclick = function(){
var file = form.elements.filename.files[0];
if(file){
sendFile(file);
previewImg.src = URL.createObjectURL(file)
}else{
alert("Not file.");
}
};
}
</script>
</head>
<body>
<h1>Story Time</h1>
<h4>Upload the picture about your book</h4>
<div>
<form id="myform">
<input type="file" name="filename">
<input type="button" name="button" value="Send">
</form>
</div>
<img id="previewImg" width="600" alt="Preview}" />
<h4>A MP3 file will be generated from your picture and then delivered to your email address.</h4>
</body>
</html>