-
Notifications
You must be signed in to change notification settings - Fork 16
/
form.html
39 lines (34 loc) · 1.33 KB
/
form.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
<form id="form" action="https://ihdyhw2gui.execute-api.us-east-1.amazonaws.com/stage?operation=" Accept="image/*" Content-Type="application/json" method="POST">
Operation: <input type="text" name="operation" id="operation"><br>
Options: <input type="text" name="options"><br>
Your image: <input type="file" name="pic" id="pic" onchange="getBase64()"><br>
<input type="hidden" name="base64Image" id="base64Image" value="">
<img src="" height="200" alt="Image preview..." style="display:none">
<input type="submit" value="Submit">
</form>
<script>
var operation = document.getElementById("operation");
var form_el = document.getElementById("form");
var base64Image = document.getElementById("base64Image");
var preview = document.querySelector('img');
var pic = null;
function getBase64() {
pic = document.getElementById("pic");
var reader = new FileReader();
var file = pic.files[0];
if (file) {
reader.readAsDataURL(file);
}
reader.onload = function () {
base64Image.value = reader.result.replace("data:image/png;base64,", "");
preview.src = reader.result;
preview.style.display = 'block';
};
reader.onerror = function (error) {
console.log('Error: ', error);
};
}
form_el.addEventListener("submit", function(e) {
form_el.action += operation.value;
});
</script>