-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
102 lines (85 loc) · 2.66 KB
/
index.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Parse Image Metadata</title>
<style>
body {
display: flex;
height: 100vh;
margin: 0;
font-family: Arial, sans-serif;
}
.frame {
margin: 10px;
flex: 1;
}
.frame img {
max-width: 100%;
max-height: 100%;
}
.drop-area {
border: 2px dashed #aaa;
background-color: #f9f9f9;
display: flex;
justify-content: center;
align-items: center;
}
.text-frame {
border: 2px solid #ddd;
padding: 20px;
overflow: auto;
}
</style>
</head>
<body>
<div class="frame drop-area" id="imageFrame">
<p>Drop an image here</p>
</div>
<pre class="frame text-frame" id="responseFrame"></pre>
<script>
const imageFrame = document.getElementById('imageFrame');
const responseFrame = document.getElementById('responseFrame');
// Prevent default drag behaviors
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(event => {
imageFrame.addEventListener(event, e => e.preventDefault());
});
// Handle dropped files
imageFrame.addEventListener('drop', (event) => {
const file = event.dataTransfer.files[0];
if (file && file.type.startsWith('image/')) {
displayImage(file);
uploadImage(file);
}
});
function displayImage(file) {
const reader = new FileReader();
reader.onload = (e) => {
imageFrame.innerHTML = `<img src="${e.target.result}" alt="Dropped image">`;
};
reader.readAsDataURL(file);
}
function uploadImage(file) {
const formData = new FormData();
formData.append('image', file);
fetch('/api/parse', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.error) {
responseFrame.textContent = data.error;
}
else {
responseFrame.innerHTML = JSON.stringify(data, null, 2);
}
})
.catch(error => {
responseFrame.textContent = 'Error: ' + error.message;
});
}
</script>
</body>
</html>