Beispiel #1
0
        public ActionResult Download(DownloadModel model)
        {
            var file = this.GetStoredFile(model);

            var stream = this.FileStorageService.Get(file.StoragePath);

            return File(stream, file.ContentType, file.Filename);
        }
Beispiel #2
0
        private BusinessLogic.Data.StoredFile GetStoredFile(DownloadModel model)
        {
            using (var db = new BusinessLogic.Data.SharingDataContext())
            {
                var shareToken = ShareToken.Parse(model.ShareToken);
                var shareTokenBytes = shareToken.GetBytes();
                byte[] sharePassword = null;
                BusinessLogic.Data.StoredFile storedFile;

                if (shareToken.FileID > 0)
                {
                    var sharedFile = db.SharedFiles
                        .Where(x => x.ShareToken == shareTokenBytes
                            && x.ExpirationDateTime > DateTime.UtcNow)
                        .Include(i => i.StoredFile)
                        .SingleOrDefault();

                    sharePassword = sharedFile.Password;
                    storedFile = sharedFile.StoredFile;
                }
                else
                {
                    var sharedFileSet = db.SharedFileSets
                        .Where(x => x.ShareToken == shareTokenBytes
                            && x.ExpirationDateTime > DateTime.UtcNow)
                        .Include(s => s.FileSet.StoredFiles)
                        .SingleOrDefault();

                    sharePassword = sharedFileSet.Password;
                    storedFile = sharedFileSet.FileSet.StoredFiles.SingleOrDefault(x => x.FileID == model.FileID);
                }

                if (!ValidatePasswordCookie(sharePassword))
                {
                    return null;
                }

                return storedFile;
            }
        }
Beispiel #3
0
        public ActionResult Thumb(DownloadModel model)
        {
            var file = this.GetStoredFile(model);
            var thumbFileName = string.Concat(file.StoragePath, ".jpg");
            System.IO.Stream stream;

            //TODO: This isn't always the case with images because the content type is sometimes not image/*
            // for images if the uploader control doesn't set them that way (e.g. uploadify)
            if (!file.ContentType.StartsWith("image"))
            {
                return File("~/images/trans.gif", "image/gif");
            }

            if (this.FileStorageService.Exists(thumbFileName))
            {
                stream = this.FileStorageService.Get(thumbFileName);

                return File(stream, "image/jpeg");
            }

            stream = BusinessLogic.Helpers.ThumbnailHelper.CreateThumbnail(this.FileStorageService.Get(file.StoragePath));

            this.FileStorageService.Put(stream, thumbFileName);
            stream.Position = 0;

            return File(stream, "image/jpeg");
        }