fix: raw body upload (no base64), remove form parsing, bump 1.0.20
Deploy loadtest / validate (push) Waiting to run
Deploy loadtest / validate (push) Waiting to run
This commit is contained in:
+35
-43
@@ -193,58 +193,50 @@ async function uploadAll() {
|
||||
fileSummary.textContent = summary;
|
||||
}
|
||||
|
||||
/** uploadFileHTTP(f, idx) — загрузить файл через HTTP POST (base64, с retry) */
|
||||
/** uploadFileHTTP(f, idx) — загрузить файл как raw body (без base64) */
|
||||
function uploadFileHTTP(f, idx) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function () {
|
||||
var dataUrl = reader.result;
|
||||
var startTime = Date.now();
|
||||
var RETRY = 3;
|
||||
var startTime = Date.now();
|
||||
var RETRY = 3;
|
||||
|
||||
function doUpload(attempt) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', '/upload');
|
||||
xhr.timeout = 300000;
|
||||
function doUpload(attempt) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', '/upload');
|
||||
xhr.timeout = 300000;
|
||||
xhr.setRequestHeader('X-File-Name', encodeURIComponent(f.name));
|
||||
xhr.setRequestHeader('X-File-Size', f.size);
|
||||
|
||||
xhr.upload.onprogress = function (e) {
|
||||
if (e.lengthComputable) {
|
||||
f.progress = Math.round(e.loaded / e.total * 100);
|
||||
renderTable();
|
||||
}
|
||||
};
|
||||
xhr.upload.onprogress = function (e) {
|
||||
if (e.lengthComputable) {
|
||||
f.progress = Math.round(e.loaded / e.total * 100);
|
||||
renderTable();
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onload = function () {
|
||||
try {
|
||||
var r = JSON.parse(xhr.responseText);
|
||||
resolve({ bytes: r.bytes, elapsed_ms: Date.now() - startTime });
|
||||
} catch (e) {
|
||||
if (attempt < RETRY) { doUpload(attempt + 1); return; }
|
||||
reject(new Error('Bad response'));
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = function () {
|
||||
xhr.onload = function () {
|
||||
try {
|
||||
var r = JSON.parse(xhr.responseText);
|
||||
resolve({ bytes: r.bytes, elapsed_ms: Date.now() - startTime });
|
||||
} catch (e) {
|
||||
if (attempt < RETRY) { doUpload(attempt + 1); return; }
|
||||
reject(new Error('Network error'));
|
||||
};
|
||||
reject(new Error('Bad response'));
|
||||
}
|
||||
};
|
||||
|
||||
xhr.ontimeout = function () {
|
||||
if (attempt < RETRY) { doUpload(attempt + 1); return; }
|
||||
reject(new Error('Timeout'));
|
||||
};
|
||||
xhr.onerror = function () {
|
||||
if (attempt < RETRY) { doUpload(attempt + 1); return; }
|
||||
reject(new Error('Network error'));
|
||||
};
|
||||
|
||||
var form = new FormData();
|
||||
form.append('data', dataUrl);
|
||||
form.append('name', f.name);
|
||||
form.append('orig_size', f.size);
|
||||
xhr.send(form);
|
||||
}
|
||||
xhr.ontimeout = function () {
|
||||
if (attempt < RETRY) { doUpload(attempt + 1); return; }
|
||||
reject(new Error('Timeout'));
|
||||
};
|
||||
|
||||
doUpload(1);
|
||||
};
|
||||
reader.onerror = function () { reject(new Error('Read error')); };
|
||||
reader.readAsDataURL(f.file);
|
||||
xhr.send(f.file);
|
||||
}
|
||||
|
||||
doUpload(1);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user