示例#1
0
        private bool FileIsInvalid(IFormFile file, out JsonResult errorJson)
        {
            if (file == null)
            {
                errorJson = Json(new { success = false, message = "", elementId = ProfilePictureErrorId });
                return(true);
            }
            if (_fileUploadService.InvalidExtension(file))
            {
                errorJson = Json(new { success = false, message = "Only JPG and PNG images are allowed.", elementId = ProfilePictureErrorId });
                return(true);
            }
            if (_fileUploadService.InvalidNameLength(file))
            {
                errorJson = Json(new { success = false, message = "The filename is too short.", elementId = ProfilePictureErrorId });
                return(true);
            }

            if (_fileUploadService.InvalidSize(file))
            {
                errorJson = Json(new { success = false, message = "The file can't be larger than 5 MB.", elementId = ProfilePictureErrorId });
                return(true);
            }
            errorJson = null;
            return(false);
        }