Exemple #1
0
        public ActionResult Download(FileGetModel model)
        {
            var sharedFile = _shareService.GetByUrlHash(model.Item, model.Key);

            if (sharedFile == null)
            {
                return(RedirectToAction("Index", "Files", new { id = model.Item }));
            }
            var urlPart = Utility.FromHexStr(sharedFile.UrlPart);//Utility.DecryptFromHex(model.Item, sharedFile.UrlKey);

            urlPart = urlPart.Replace(@"\", "/");
            //var filePath = GetHost() + "/" + StorageUtility.VaultSharedPath + "/" + urlPart;
            //return Redirect(filePath);
            var sharedRootPath = StorageUtility.GetVaultSharedRootPath();
            var filePath       = Path.Combine(sharedRootPath, urlPart);
            //var filePath = Path.Combine(Server.MapPath("~"), StorageUtility.VaultSharedPath + "\\" + urlPart);
            var downloadName = Path.GetFileName(filePath);

            if (!StorageUtility.NeedImpersonation(filePath))
            {
                return(File(filePath, "application/octet-stream", downloadName));
            }
            using (StorageUtility.GetImpersonator())
            {
                var bytes = System.IO.File.ReadAllBytes(filePath);
                var fcr   = new FileContentResult(bytes, "application/octet-stream")
                {
                    FileDownloadName = downloadName
                };
                return(fcr);
                //return File(filePath, "application/octet-stream", downloadName);
            }
        }
Exemple #2
0
        // GET: Files
        public ActionResult Index(string id)
        {
            var fileModel = new FileGetModel {
                Item = id
            };

            return(View(fileModel));
        }
        public FileGetModel GetImageFile(string path)
        {
            var model     = new FileGetModel();
            var imagePath = Path.Combine(hostingEnvironment.ContentRootPath, AvatarFolder + "\\userName\\" + path);

            if (IsImageExist(imagePath))
            {
                model.File     = System.IO.File.OpenRead(imagePath);
                model.FileType = GetImageTypeFromPath(imagePath);
                return(model);
            }

            return(null);
        }