Skip to content

Commit

Permalink
[document_repository] Uploading file too large not reporting correctly (
Browse files Browse the repository at this point in the history
#9174)

Fixes #9158
  • Loading branch information
kongtiaowang authored Apr 11, 2024
1 parent 9e66110 commit d21ecde
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 6 additions & 0 deletions modules/document_repository/jsx/uploadForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ class DocUploadForm extends Component {
'error'
);
}
if (resp.status == 400) {
swal.fire('Something went wrong',
JSON.parse(resp.response).message,
'error'
);
}
}
}).catch((error) => {
console.error(error);
Expand Down
14 changes: 6 additions & 8 deletions modules/document_repository/php/files.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -316,20 +316,18 @@ class Files extends \NDB_Page
if (!is_array($body)) {
throw new \LorisException("Expected parsed body to be an array");
}

$category = $body['category']; // required
if (!\Utility::valueIsPositiveInteger($category)) {
// $category is a string representation of an ID, and so should be
// at least equal to zero.
return new \LORIS\Http\Response\JSON\BadRequest(self::BAD_CATEGORY);
}

$uploadedFiles = $request->getUploadedFiles()['files'] ?? null;

if (is_null($uploadedFiles)) {
header("HTTP/1.1 413 Too_large");
exit;
}
$category = $body['category']; // required
if (!\Utility::valueIsPositiveInteger(strval($category))) {
// $category is a string representation of an ID, and so should be
// at least equal to zero.
return new \LORIS\Http\Response\JSON\BadRequest(self::BAD_CATEGORY);
}

$uploadedFiles = is_array($uploadedFiles)
? $uploadedFiles : [$uploadedFiles];
Expand Down

0 comments on commit d21ecde

Please sign in to comment.