File size: 1,624 Bytes
0de5455
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Camera Image</title>
    </head>
    <body>
        <h1>Upload Image</h1>
        <form id="uploadForm" enctype="multipart/form-data" method="post" action="/upload">
            <input type="file" name="photo">
            <button type="submit">Upload</button>
        </form>
        <div id="message"></div>
        <h1>Latest Image</h1>
        <img id="cameraImage" src="/image" alt="Image" style="width:100%;">
        <script>
            document.getElementById('uploadForm').addEventListener('submit', function(event) {
                event.preventDefault();
                var formData = new FormData(this);
                fetch('/upload', {
                    method: 'POST',
                    body: formData
                })
                .then(response => {
                    if (response.ok) {
                        return response.text();
                    }
                    throw new Error('Network response was not ok.');
                })
                .then(data => {
                    document.getElementById('message').innerText = data;
                    var image = document.getElementById("cameraImage");
                    image.src = "/image?" + new Date().getTime();
                })
                .catch(error => {
                    document.getElementById('message').innerText = 'Error: ' + error.message;
                });
            });
        </script>
    </body>
    </html>