limits max size of all uploaded files at the one time [fixes SCI-740]

This commit is contained in:
zmagod 2016-12-07 09:02:04 +01:00
parent a376118cd8
commit 9f1e436623
2 changed files with 19 additions and 0 deletions

View file

@ -108,6 +108,7 @@ function filesValidator(ev, fileInputs, fileTypeEnum, canBeEmpty) {
if (fileInputs.length) {
var filesPresentValid = canBeEmpty || filesPresentValidator(ev, fileInputs);
var filesSizeValid = filesSizeValidator(ev, fileInputs, fileTypeEnum);
// File spoof check is done on server-side only
filesValid = filesPresentValid && filesSizeValid;
}
@ -142,11 +143,28 @@ function filesSizeValidator(ev, fileInputs, fileTypeEnum) {
}
};
function checkFilesTotalSize(fileInputs) {
if (!fileInputs || fileInputs < 2) {
return ;
}
var size = 0;
_.each(fileInputs, function(fileInput) {
var file = fileInput.files[0]
size += file.size;
})
if (size > fileTypeEnum) {
return "<%= I18n.t('general.file.total_size', size: Constants::FILE_MAX_SIZE_MB) %>".strToErrorFormat();
}
}
// Check if any file exceeds allowed size limit
var filesSizeValid = true;
_.each(fileInputs, function(fileInput) {
var file = fileInput.files[0];
var assetError = getFileTooBigError(file);
var assetError = checkFilesTotalSize(fileInputs);
if (assetError) {
renderFormError(ev, fileInput, assetError, false, "data-error='file-size'");
filesSizeValid = false;

View file

@ -1440,6 +1440,7 @@ en:
private: "private"
search: "Search"
file:
total_size: "You can upload max %{size} MB of files at one time. Please remove one or more files and try to submit again."
size_exceeded: "File size must be less than %{file_size} MB."
blank: "You didn't select any file"
uploading: "If you leave this page, the file(s) that is/are currently uploading will not be saved! Are you sure you want to continue?"