/// <summary> /// Check whether there are any restrictions on handling the file /// </summary> /// <param name="path">Path to the file</param> /// <returns>True if the file can be handled; otherwise false</returns> protected virtual bool CanHandleFile(string path) { var result = false; var fileExtension = _fileProvider.GetFileExtension(path).Replace(".", string.Empty).ToLower(); var forbiddenUploads = GetSetting("FORBIDDEN_UPLOADS").Trim().ToLower(); if (!string.IsNullOrEmpty(forbiddenUploads)) { var forbiddenFileExtensions = new ArrayList(Regex.Split(forbiddenUploads, "\\s+")); result = !forbiddenFileExtensions.Contains(fileExtension); } var allowedUploads = GetSetting("ALLOWED_UPLOADS").Trim().ToLower(); if (string.IsNullOrEmpty(allowedUploads)) { return(result); } var allowedFileExtensions = new ArrayList(Regex.Split(allowedUploads, "\\s+")); result = allowedFileExtensions.Contains(fileExtension); return(result); }
/// <summary> /// Gets the default picture URL /// </summary> /// <param name="targetSize">The target picture size (longest side)</param> /// <param name="defaultPictureType">Default picture type</param> /// <param name="storeLocation">Store location URL; null to use determine the current store location automatically</param> /// <returns>Picture URL</returns> public virtual string GetDefaultPictureUrl(int targetSize = 0, PictureType defaultPictureType = PictureType.Entity, string storeLocation = null) { var defaultImageFileName = defaultPictureType switch { PictureType.Avatar => _settingService.GetSettingByKey("Media.Customer.DefaultAvatarImageName", SmiMediaDefaults.DefaultAvatarFileName), _ => _settingService.GetSettingByKey("Media.DefaultImageName", SmiMediaDefaults.DefaultImageFileName), }; var filePath = GetPictureLocalPath(defaultImageFileName); if (!_fileProvider.FileExists(filePath)) { return(string.Empty); } if (targetSize == 0) { var url = GetImagesPathUrl(storeLocation) + defaultImageFileName; return(url); } else { var fileExtension = _fileProvider.GetFileExtension(filePath); var thumbFileName = $"{_fileProvider.GetFileNameWithoutExtension(filePath)}_{targetSize}{fileExtension}"; var thumbFilePath = GetThumbLocalPath(thumbFileName); if (!GeneratedThumbExists(thumbFilePath, thumbFileName)) { using var image = Image.Load <Rgba32>(filePath, out var imageFormat); image.Mutate(imageProcess => imageProcess.Resize(new ResizeOptions { Mode = ResizeMode.Max, Size = CalculateDimensions(image.Size(), targetSize) })); var pictureBinary = EncodeImage(image, imageFormat); SaveThumb(thumbFilePath, thumbFileName, imageFormat.DefaultMimeType, pictureBinary); } var url = GetThumbUrl(thumbFileName, storeLocation); return(url); } }