Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[media] 413 error improperly handled #9163 - fix #9175

Merged
merged 8 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions modules/media/ajax/FileUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
}
}

Expand Down
12 changes: 7 additions & 5 deletions modules/media/jsx/uploadForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Loading