DmitrMakeev commited on
Commit
89997b5
·
verified ·
1 Parent(s): c091b0c

Update se_mes_im2.html

Browse files
Files changed (1) hide show
  1. se_mes_im2.html +49 -59
se_mes_im2.html CHANGED
@@ -1,60 +1,50 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Camera Image</title>
7
- </head>
8
- <body>
9
- <h1>Upload Image</h1>
10
- <form id="uploadForm" enctype="multipart/form-data" method="post" action="/upload">
11
- <input type="file" name="photo">
12
- <button type="submit">Upload</button>
13
- </form>
14
- <div id="message"></div>
15
- <div id="serverUrl"></div> <!-- Добавлено для вывода URL сервера -->
16
- <h1>Latest Image</h1>
17
- <img id="cameraImage" src="/image" alt="Image" style="width:100%;">
18
- <script>
19
- document.addEventListener('DOMContentLoaded', function() {
20
- // Отправляем POST-запрос для получения URL сервера
21
- fetch('/own_url', {
22
- method: 'POST',
23
- headers: {
24
- 'Content-Type': 'application/x-www-form-urlencoded'
25
- },
26
- body: 'own_url=http://your-server-url.com' // Замените на ваш URL сервера
27
- })
28
- .then(response => response.text())
29
- .then(ownUrl => {
30
- // Выводим URL сервера на страницу
31
- document.getElementById('serverUrl').innerText = 'Server URL: ' + ownUrl;
32
- // Обрабатываем отправку формы
33
- document.getElementById('uploadForm').addEventListener('submit', function(event) {
34
- event.preventDefault();
35
- var formData = new FormData(this);
36
- fetch('/upload', {
37
- method: 'POST',
38
- body: formData
39
- })
40
- .then(response => {
41
- if (response.ok) {
42
- return response.text();
43
- }
44
- throw new Error('Network response was not ok.');
45
- })
46
- .then(data => {
47
- document.getElementById('message').innerText = data;
48
- // Обновляем src изображения, добавляя полученный URL сервера
49
- var image = document.getElementById("cameraImage");
50
- image.src = ownUrl + "/image?" + new Date().getTime();
51
- })
52
- .catch(error => {
53
- document.getElementById('message').innerText = 'Error: ' + error.message;
54
- });
55
- });
56
- });
57
  });
58
- </script>
59
- </body>
60
- </html>
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Upload Image</title>
7
+ </head>
8
+ <body>
9
+ <h1>Upload Image</h1>
10
+ <form id="uploadForm">
11
+ <input type="file" id="fileInput" accept="image/*">
12
+ <button type="submit">Upload</button>
13
+ </form>
14
+ <div id="message"></div>
15
+ <div id="imageUrl"></div>
16
+
17
+ <script>
18
+ document.getElementById('uploadForm').addEventListener('submit', function(event) {
19
+ event.preventDefault();
20
+ const fileInput = document.getElementById('fileInput');
21
+ const file = fileInput.files[0];
22
+ if (!file) {
23
+ document.getElementById('message').innerText = 'No file selected';
24
+ return;
25
+ }
26
+
27
+ const formData = new FormData();
28
+ formData.append('file', file);
29
+
30
+ fetch('https://api.green-api.com/waInstance1101952913/uploadFile/fb4986a9d9cb40ef9be6c7b08cb9c98b7a3b1dc8c6834b0b92', {
31
+ method: 'POST',
32
+ headers: {
33
+ 'Content-Type': 'image/jpeg'
34
+ },
35
+ body: formData
36
+ })
37
+ .then(response => response.json())
38
+ .then(data => {
39
+ if (data.url) {
40
+ document.getElementById('message').innerText = 'File uploaded successfully';
41
+ document.getElementById('imageUrl').innerHTML = `<a href="${data.url}" target="_blank">Download Image</a>`;
42
+ } else {
43
+ document.getElementById('message').innerText = 'Failed to upload file';
44
+ }
45
+ })
46
+ .catch(error => {
47
+ document.getElementById('message').innerText = 'Error: ' + error.message;
 
 
 
 
 
 
 
 
 
48
  });
49
+ });
50
+ </script>