Handle 413 responses from Nginx when uploading files too large

Fixes #5171
This commit is contained in:
Frédéric Guillot
2023-04-14 20:11:51 -07:00
committed by Frédéric Guillot
parent 0b1c2011ed
commit bd50288030
3 changed files with 17 additions and 4 deletions

View File

@@ -108,7 +108,7 @@ KB.http.postForm = function (url, formElement) {
return (new KB.http.request('POST', url, {}, formData)).execute();
};
KB.http.uploadFile = function (url, file, csrf, onProgress, onComplete, onError, onServerError) {
KB.http.uploadFile = function (url, file, csrf, onProgress, onComplete, onError, onServerError, onRequestTooLarge) {
var fd = new FormData();
fd.append('files[]', file);
fd.append('csrf_token', csrf);
@@ -123,6 +123,12 @@ KB.http.uploadFile = function (url, file, csrf, onProgress, onComplete, onError,
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
onComplete();
} else if (xhr.status === 413) {
if (typeof onRequestTooLarge !== 'undefined') {
onRequestTooLarge();
} else {
onError(xhr.responseText);
}
} else if (typeof onServerError !== 'undefined') {
onServerError(JSON.parse(xhr.responseText));
}