remove uploadFile() method as it is not used
This commit is contained in:
parent
9dd6dc7523
commit
e2af4f74c3
|
@ -412,99 +412,6 @@ Oqtane.Interop = {
|
|||
fileinput.value = '';
|
||||
return success;
|
||||
},
|
||||
uploadFile: function (posturl, folder, id, antiforgerytoken, jwt, chunksize, totalsize, file) {
|
||||
var fileinput = document.getElementById('FileInput_' + id);
|
||||
var progressinfo = document.getElementById('ProgressInfo_' + id);
|
||||
var progressbar = document.getElementById('ProgressBar_' + id);
|
||||
|
||||
if (file === null && fileinput !== null) {
|
||||
file = fileinput.files[0];
|
||||
totalsize = file.size;
|
||||
}
|
||||
|
||||
if (progressinfo !== null && progressbar !== null && fileinput.files.length === 1) {
|
||||
progressinfo.setAttribute("style", "display: inline;");
|
||||
progressinfo.innerHTML = file.name;
|
||||
progressbar.setAttribute("style", "width: 100%; display: inline;");
|
||||
progressbar.value = 0;
|
||||
}
|
||||
|
||||
if (!chunksize) {
|
||||
chunksize = 1; // 1 MB default
|
||||
}
|
||||
const chunkSize = chunksize * (1024 * 1024);
|
||||
let uploadSize = 0;
|
||||
const totalParts = Math.ceil(file.size / chunkSize);
|
||||
let partCount = 0;
|
||||
const maxThreads = 1;
|
||||
let threadCount = 1;
|
||||
|
||||
const uploadPart = () => {
|
||||
const start = partCount * chunkSize;
|
||||
const end = Math.min(start + chunkSize, file.size);
|
||||
const chunk = file.slice(start, end);
|
||||
|
||||
while (threadCount > maxThreads) {
|
||||
// wait for thread to become available
|
||||
}
|
||||
threadCount++;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
let formdata = new FormData();
|
||||
formdata.append('__RequestVerificationToken', antiforgerytoken);
|
||||
formdata.append('folder', folder);
|
||||
formdata.append('formfile', chunk, file.name);
|
||||
|
||||
var credentials = 'same-origin';
|
||||
var headers = new Headers();
|
||||
headers.append('PartCount', partCount + 1);
|
||||
headers.append('TotalParts', totalParts);
|
||||
if (jwt !== "") {
|
||||
headers.append('Authorization', 'Bearer ' + jwt);
|
||||
credentials = 'include';
|
||||
}
|
||||
|
||||
return fetch(posturl, {
|
||||
method: 'POST',
|
||||
headers: headers,
|
||||
credentials: credentials,
|
||||
body: formdata
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
if (progressinfo !== null) {
|
||||
progressinfo.innerHTML = ' Error: ' + response.statusText;
|
||||
}
|
||||
throw new Error('Failed');
|
||||
}
|
||||
if (progressbar !== null) {
|
||||
progressbar.value = 1;
|
||||
}
|
||||
return;
|
||||
})
|
||||
.then(data => {
|
||||
partCount++;
|
||||
if (progressbar !== null) {
|
||||
uploadSize += chunk.size;
|
||||
var percent = Math.ceil((uploadSize / totalsize) * 100);
|
||||
progressbar.value = (percent / 100);
|
||||
}
|
||||
threadCount--;
|
||||
if (partCount < totalParts) {
|
||||
uploadPart().then(resolve).catch(reject);
|
||||
}
|
||||
else {
|
||||
resolve(data);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return uploadPart();
|
||||
},
|
||||
refreshBrowser: function (verify, wait) {
|
||||
async function attemptReload (verify) {
|
||||
if (verify) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user