DmitrMakeev commited on
Commit
d4ff5bb
1 Parent(s): 51fa69d

Update se_mes_im2.html

Browse files
Files changed (1) hide show
  1. se_mes_im2.html +34 -15
se_mes_im2.html CHANGED
@@ -54,6 +54,22 @@
54
  cursor: pointer;
55
  text-decoration: underline;
56
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  </style>
58
  </head>
59
  <body>
@@ -66,29 +82,32 @@
66
  <input type="file" name="file">
67
  <button type="submit">Upload</button>
68
  </form>
 
 
 
69
  <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/toastify-js"></script>
70
  <script>
71
  document.getElementById('uploadForm').addEventListener('submit', function(event) {
72
  event.preventDefault();
73
  var formData = new FormData(this);
74
- fetch('/upload', {
75
- method: 'POST',
76
- body: formData
77
- })
78
- .then(response => {
79
- if (response.ok) {
80
- return response.text();
81
  }
82
- throw new Error('Network response was not ok.');
83
- })
84
- .then(data => {
85
- var fullUrl = data.split('saved to ')[1];
86
  document.getElementById('imageUrl').innerText = fullUrl;
87
  displayMedia(fullUrl);
88
- })
89
- .catch(error => {
90
- console.error('Error:', error);
91
- });
92
  });
93
  function displayMedia(url) {
94
  var mediaContainer = document.getElementById('mediaContainer');
 
54
  cursor: pointer;
55
  text-decoration: underline;
56
  }
57
+ #progressBarContainer {
58
+ width: 80%;
59
+ margin: 20px auto;
60
+ background-color: #ddd;
61
+ border-radius: 13px;
62
+ padding: 3px;
63
+ }
64
+ #progressBar {
65
+ width: 0%;
66
+ height: 20px;
67
+ background-color: #4CAF50;
68
+ border-radius: 10px;
69
+ text-align: center;
70
+ line-height: 20px;
71
+ color: white;
72
+ }
73
  </style>
74
  </head>
75
  <body>
 
82
  <input type="file" name="file">
83
  <button type="submit">Upload</button>
84
  </form>
85
+ <div id="progressBarContainer">
86
+ <div id="progressBar">0%</div>
87
+ </div>
88
  <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/toastify-js"></script>
89
  <script>
90
  document.getElementById('uploadForm').addEventListener('submit', function(event) {
91
  event.preventDefault();
92
  var formData = new FormData(this);
93
+ var request = new XMLHttpRequest();
94
+ request.open('POST', '/upload');
95
+ request.upload.addEventListener('progress', function(event) {
96
+ if (event.lengthComputable) {
97
+ var percentComplete = (event.loaded / event.total) * 100;
98
+ document.getElementById('progressBar').style.width = percentComplete + '%';
99
+ document.getElementById('progressBar').innerText = Math.round(percentComplete) + '%';
100
  }
101
+ }, false);
102
+ request.addEventListener('load', function(event) {
103
+ var response = event.target.responseText;
104
+ var fullUrl = response.split('saved to ')[1];
105
  document.getElementById('imageUrl').innerText = fullUrl;
106
  displayMedia(fullUrl);
107
+ document.getElementById('progressBar').style.width = '0%';
108
+ document.getElementById('progressBar').innerText = '0%';
109
+ }, false);
110
+ request.send(formData);
111
  });
112
  function displayMedia(url) {
113
  var mediaContainer = document.getElementById('mediaContainer');