Beispiel #1
0
        private bool CheckFile(string fileName, long fileSize, out string errors)
        {
            var isFileNameValid = FileNameChecker.CheckFileName(fileName, _config["FileConstraints:PermittedExtensions"], int.Parse(_config["FileConstraints:MaxLengthFileName"]), out errors);

            var isFileSizeValid = fileSize < long.Parse(_config["FileConstraints:MaxFileSize"]);

            return(isFileNameValid && isFileSizeValid);
        }
        /// <summary>
        /// Метод проверки имени файла
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        private static bool FileNameIsNotValid(string fileName)
        {
            string error = string.Empty;

            if ((error = new FileNameChecker().Check(fileName)).Length != 0)
            {
                Console.WriteLine("Errors:\n\"{0}\" - {1}", fileName, error);
            }

            return(error.Length != 0);
        }
Beispiel #3
0
        private void CheckFileNameAndSize(IFormFile uploadedFile)
        {
            if (uploadedFile == null)
            {
                throw new CoralTimeEntityNotFoundException("File is empty");
            }

            var fileName = uploadedFile.FileName;
            var fileSize = uploadedFile.Length;

            var isFileNameValid = FileNameChecker.CheckFileName(fileName, _config["FileConstraints:PermittedExtensions"], int.Parse(_config["FileConstraints:MaxLengthFileName"]));

            var isFileSizeValid = fileSize < long.Parse(_config["FileConstraints:MaxFileSize"]);

            if (isFileNameValid != null)
            {
                throw new CoralTimeForbiddenException("FileName is Invalid");
            }

            if (!isFileSizeValid)
            {
                throw new CoralTimeForbiddenException("File size is greater than 1 Mb");
            }
        }