示例#1
0
        public async Task <IActionResult> GetInspectionImageAsync(int id)
        {
            string imageFileName = await _inspectionService.GetImageFileNameAsync(id, HttpContext.RequestAborted).ConfigureAwait(false);

            if (imageFileName == null)
            {
                return(NotFound());
            }

            string imageFilePath = Path.Join(_storageOptions.Value.ImageUploadsDirectoryPath, imageFileName);
            var    fileInfo      = new FileInfo(imageFilePath);

            if (!fileInfo.Exists)
            {
                return(NotFound());
            }

            string contentType = new FileExtensionContentTypeProvider().TryGetContentType(imageFilePath, out string result)
                ? result
                : "application/octet-stream";
            FileStream fileStream = fileInfo.OpenRead();

            return(File(fileStream, contentType, true));
        }