Сделал вывод процесса загрузски

This commit is contained in:
2026-05-21 22:30:56 +03:00
parent b903cca6e2
commit 8d5ab828c1
3 changed files with 72 additions and 12 deletions

View File

@@ -2,9 +2,11 @@
// Размер чанка в байтах
const CHUNK_SIZE = 1024 * 1024; // 1MB
async function uploadFileInChunks(file) {
async function uploadFileInChunks(file,num) {
const totalChunks = Math.ceil(file.size / CHUNK_SIZE);
for (let chunkIndex = 0; chunkIndex < totalChunks; chunkIndex++) {
@@ -15,7 +17,7 @@ async function uploadFileInChunks(file) {
// Извлекаем чанк из файла
const chunk = file.slice(start, end);
// Создаём FormData для отправки чанка
// Создаём FormData для отправки чанкаd
const formData = new FormData();
formData.append('file_chunk', chunk);
formData.append('chunk_index', chunkIndex);
@@ -26,6 +28,12 @@ async function uploadFileInChunks(file) {
await fetch('upload.php', {
method: 'POST',
body: formData
}).
then((res)=> res.json()).
then((res)=>{
document.getElementById("status_bar_"+num).innerHTML = Number(res.size/1024/1024).toFixed(2) || 0
console.log(res)
});
}
}