Exemple #1
0
        private string GetScanPreviewFilePath(Scan scan)
        {
            if (!scan.ExtensionWithDot.Equals(".jpg", StringComparison.OrdinalIgnoreCase))
            {
                return(string.Empty);
            }

            var previewsStoragePath = string.Format("{0}{1}", FileStorageProvider.GetCommonPathToScans(), "previews");

            if (!Directory.Exists(previewsStoragePath))
            {
                Directory.CreateDirectory(previewsStoragePath);
            }

            var previewPath = Path.Combine(previewsStoragePath, scan.LocalFileName);

            if (!System.IO.File.Exists(previewPath))
            {
                var fileByteStream = new FileStream(Path.Combine(FileStorageProvider.GetCommonPathToScans(), scan.ClaimId.ToString(), scan.LocalFileName),
                                                    FileMode.Open,
                                                    FileAccess.Read);
                var imagesHelper = new ImagesHelper();
                imagesHelper.GetFilePreview(fileByteStream, previewPath);
            }
            return(previewPath);
        }
        public async Task <IHttpActionResult> LoadAsync(Guid claimId)
        {
            var serverUploadFolder = string.Format("{0}{1}\\", FileStorageProvider.GetCommonPathToScans(), claimId);

            if (!Directory.Exists(serverUploadFolder))
            {
                Directory.CreateDirectory(serverUploadFolder);
            }
            var streamProvider = new CustomMultipartFormDataStreamProvider(serverUploadFolder);

            await Request.Content.ReadAsMultipartAsync(streamProvider);

            var scan = new Scan()
            {
                Id = streamProvider.ScanId, ClaimId = claimId
            };

            scan.CreateDate   = DateTime.Now;
            scan.OriginalName = streamProvider.FileData.First().Headers.ContentDisposition.FileName.Trim('"');

            _context.Scans.Add(scan);
            _context.SaveChanges();

            return(Ok(scan.Id));
        }
Exemple #3
0
        public ActionResult Get(Guid id)
        {
            var scan = _context.Scans.Find(id);

            if (scan == null)
            {
                return(HttpNotFound());
            }

            var path = Path.Combine(FileStorageProvider.GetCommonPathToScans(), scan.ClaimId.ToString(), scan.LocalFileName);

            Response.AppendHeader("Content-Disposition", "inline; filename=" + scan.OriginalName);
            return(File(path, MimeHelper.GetContentType(scan.ExtensionWithDot)));
        }