-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileReaderAndBuffer.html
37 lines (34 loc) · 1 KB
/
fileReaderAndBuffer.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
<!DOCTYPE html>
<html>
<head></head>
<body>
<form id="fileForm" enctype="multipart/form-data">
<input type="file" name="file" id="fileInput" accept="image/jpeg" />
<button type="submit">Processar</button>
</form>
<script>
const fileForm = document.getElementById("fileForm");
fileForm.addEventListener("submit", function (event) {
event.preventDefault();
const fileInput = document.getElementById("fileInput");
const file = fileInput.files[0];
if (file) {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function (e) {
const body = {
b64img: e.target.result,
};
const config = {
method: "POST",
body: JSON.stringify(body),
};
fetch(`http://localhost:3000/upload-file`, config).catch(
(err) => err
);
};
}
});
</script>
</body>
</html>