Example #1
0
        private async Task <IEnumerable <PropertyDocumentDto> > CreateThumbnail(IList <PropertyDocumentDto> files)
        {
            foreach (var file in files)
            {
                var path      = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Documents", "Images", file.Document.Name);
                var imageFile = await _commonApiClient.GetDocumentFile(new FileMetadata { FileUNCPath = file.Document.RelativePath });

                using (var stream = new FileStream(path, FileMode.Create))
                {
                    var ms = new MemoryStream(imageFile.FileContent);
                    ms.WriteTo(stream);
                }
                using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read))
                {
                    var resourceImage = Image.FromStream(stream);
                    var thumb         = resourceImage.GetThumbnailImage(120, 120, () => false, IntPtr.Zero);
                    path = Path.ChangeExtension(path, "thumb");
                    if (!System.IO.File.Exists(path))
                    {
                        thumb.Save(path);
                    }
                    file.ImageThumbnailContent = System.IO.File.ReadAllBytes(path);
                    stream.Dispose();
                }
            }

            return(files);
        }
Example #2
0
        public async Task <IActionResult> ViewImage(int id)
        {
            var document = _commonFacadeApiClient.GetDocument(id).Result;
            var file     = await _commonFacadeApiClient.GetDocumentFile(new FileMetadata { FileUNCPath = document.RelativePath });

            return(PartialView(file));
        }