public Stream GetImage(string key) { ExceptionHelper.ThrowIfNullOrWhiteSpace(key, paramName: "key"); string query; key = FormatKey(key, out query); string extension; var processors = ImageProcessor.ParseQuery(query, out extension); if (processors.Length > 0) { if (String.IsNullOrWhiteSpace(extension)) { extension = Path.GetExtension(key); } var formatQuery = String.Join("|", processors.Select(p => p.Arguments.ToQuery())); if (processors.Length > 1) { formatQuery = new Flh.Security.MD5().Encrypt(formatQuery); } var currentkey = String.Format("temp/{0}@{1}", key, formatQuery); if (!currentkey.EndsWith(extension)) { currentkey += extension; } try { var stream = GetFile(FileId.FromFileId(currentkey)); if (stream == null) { using (var source = GetFile(FileId.FromFileId(key))) { if (source == null) { return(null); } stream = ImageProcessor.Process(source, new ImageProcessorSetting(), processors); _OssClient.PutObject(_BucketName, currentkey, stream, new ObjectMetadata()); stream.Position = 0; return(stream); } } return(stream); } catch (OssException ex) { if (ex.ErrorCode == OssErrorCode.NoSuchKey) { using (var source = GetFile(FileId.FromFileId(key))) { var stream = ImageProcessor.Process(source, new ImageProcessorSetting(), processors); _OssClient.PutObject(_BucketName, currentkey, stream, new ObjectMetadata()); stream.Position = 0; return(stream); } } else { throw ex; } } } else { return(GetFile(FileId.FromFileId(key))); } }
public Stream GetImage(string key) { ExceptionHelper.ThrowIfNullOrWhiteSpace(key, paramName: "key"); string query; key = FormatKey(key, out query); string extension; var processors = ImageProcessor.ParseQuery(query, out extension); if (processors.Length > 0) { if (String.IsNullOrWhiteSpace(extension)) extension = Path.GetExtension(key); var formatQuery = String.Join("|", processors.Select(p => p.Arguments.ToQuery())); if (processors.Length > 1) formatQuery = new Flh.Security.MD5().Encrypt(formatQuery); var currentkey = String.Format("temp/{0}@{1}", key, formatQuery); if (!currentkey.EndsWith(extension)) currentkey += extension; try { var stream = GetFile(FileId.FromFileId(currentkey)); if (stream == null) { using (var source = GetFile(FileId.FromFileId(key))) { if (source == null) return null; stream = ImageProcessor.Process(source, new ImageProcessorSetting(), processors); _OssClient.PutObject(_BucketName, currentkey, stream, new ObjectMetadata()); stream.Position = 0; return stream; } } return stream; } catch (OssException ex) { if (ex.ErrorCode == OssErrorCode.NoSuchKey) { using (var source = GetFile(FileId.FromFileId(key))) { var stream = ImageProcessor.Process(source, new ImageProcessorSetting(), processors); _OssClient.PutObject(_BucketName, currentkey, stream, new ObjectMetadata()); stream.Position = 0; return stream; } } else { throw ex; } } } else { return GetFile(FileId.FromFileId( key)); } }