public Task <(bool Success, string FileName, Stream FileStream)> TryGetImageStream(string requestUrl, ThumbCropConfig config)
        {
            var filePath = ImageSourceTools.CleanFilePath(requestUrl, config.UrlPattern);

            filePath = string.IsNullOrWhiteSpace(filePath)
                ? Path.Combine(config.BasePath, config.NotFoundFile)
                : Path.Combine(config.BasePath, filePath);

            if (string.IsNullOrWhiteSpace(filePath) || !File.Exists(filePath))
            {
                return(ImageSourceTools.None);
            }

            return(Task.FromResult <(bool Success, string FileName, Stream FileStream)>(
                       (true,
                        Path.GetFileName(filePath),
                        File.OpenRead(filePath))
                       ));
        }
Ejemplo n.º 2
0
        public async Task <(bool Success, string FileName, Stream FileStream)> TryGetImageStream(string requestUrl, ThumbCropConfig config)
        {
            var filePath = ImageSourceTools.CleanFilePath(requestUrl, config.UrlPattern);

            var fileName      = Path.GetFileName(filePath);
            var containerName = Path.GetDirectoryName(filePath);

            if (!_containers.Contains(containerName))
            {
                return(await ImageSourceTools.None);
            }

            var container = GetContainer(containerName);
            var blob      = container.GetBlobReference(fileName);

            if (!(await blob.ExistsAsync()))
            {
                return(await ImageSourceTools.None);
            }

            var memoryStream = new MemoryStream();
            await blob.DownloadToStreamAsync(memoryStream);

            memoryStream.Position = 0;
            return(true, fileName, memoryStream);
        }