public bool ProcessStream(Stream fileContent, string extension, ITextLocalizer localizer) { extension = extension.TrimToEmpty().ToLowerInvariant(); if (IsDangerousExtension(extension)) { ErrorMessage = "Unsupported file extension!"; return(false); } CheckResult = ImageCheckResult.InvalidImage; ErrorMessage = null; ImageWidth = 0; ImageHeight = 0; IsImage = false; var success = false; storage.PurgeTemporaryFiles(); var basePath = "temporary/" + Guid.NewGuid().ToString("N"); try { try { FileSize = fileContent.Length; fileContent.Seek(0, System.IO.SeekOrigin.Begin); TemporaryFile = storage.WriteFile(basePath + extension, fileContent, false); if (IsImageExtension(extension)) { IsImage = true; success = ProcessImageStream(fileContent, localizer); } else { success = true; } } catch (Exception ex) { ErrorMessage = ex.Message; ex.Log(Logger); success = false; return(success); } } finally { if (!success) { if (!ThumbFile.IsNullOrEmpty()) { storage.DeleteFile(ThumbFile); } if (!TemporaryFile.IsNullOrEmpty()) { storage.DeleteFile(TemporaryFile); } } fileContent.Dispose(); } return(success); }