diff --git a/modules/media/ajax/FileUpload.php b/modules/media/ajax/FileUpload.php index 5af60b691ae..dae1bab8cac 100644 --- a/modules/media/ajax/FileUpload.php +++ b/modules/media/ajax/FileUpload.php @@ -117,12 +117,9 @@ function uploadFile() $language = isset($_POST['language']) ? $_POST['language'] : null; // If required fields are not set, show an error - if (empty($_FILES)) { - echo showMediaError( - "File could not be uploaded successfully. - Please contact the administrator.", - 400 - ); + if (empty($_POST)) { + echo showMediaError("File too large!", 413); + return; } if (!isset($pscid, $visit)) { @@ -220,7 +217,7 @@ function uploadFile() echo showMediaError("Could not upload the file. Please try again!", 500); } } else { - echo showMediaError("Could not upload the file. Please try again!", 500); + echo showMediaError("File too Large!", 500); } } diff --git a/modules/media/jsx/uploadForm.js b/modules/media/jsx/uploadForm.js index b1af9aad307..93e590a0537 100644 --- a/modules/media/jsx/uploadForm.js +++ b/modules/media/jsx/uploadForm.js @@ -351,11 +351,13 @@ class MediaUploadForm extends Component { console.error(xhr.status + ': ' + xhr.statusText); let msg = 'Upload error!'; if (xhr.response) { - const resp = JSON.parse(xhr.response); - if (resp.message) { - msg = resp.message; + if (xhr.statusText) { + msg = JSON.parse(xhr.response).message; } } + if (xhr.status === 413) { + msg = JSON.stringify('File too large!'); + } this.setState({ errorMessage: msg, @@ -367,8 +369,8 @@ class MediaUploadForm extends Component { xhr.addEventListener('error', () => { console.error(xhr.status + ': ' + xhr.statusText); - let msg = xhr.response && xhr.response.message - ? xhr.response.message + let msg = xhr.response && JSON.parse(xhr.response).message + ? JSON.parse(xhr.response).message : 'Upload error!'; this.setState({ errorMessage: msg,