Ejemplo n.º 1
0
 public EntryInfo Search(Guid id)
 {
     using (var db = new FileDB(_filedbPath, FileAccess.Read))
     {
         return db.Search(id);
     }
 }
Ejemplo n.º 2
0
        public ActionResult Download(string id)
        {
            // Using a classic way to download a file, insted of FileContentResult mode. 
            // Optimize for big files (download on demand)

            using (var db = new FileDB(pathDB, FileAccess.Read))
            {
                var info = db.Search(Guid.Parse(id));

                Response.Buffer = false;
                Response.BufferOutput = false;
                Response.ContentType = info.MimeType;
                Response.AppendHeader("Content-Length", info.FileLength.ToString());
                Response.AppendHeader("content-disposition", "attachment; filename=" + info.FileName);

                db.Read(info.ID, Response.OutputStream);

                return new EmptyResult();
            }
        }
Ejemplo n.º 3
0
        public ActionResult Thumbnail(string id)
        {
            using (var db = new FileDB(pathDB, FileAccess.Read))
            {
                var info = db.Search(Guid.Parse(id));

                if (!info.MimeType.StartsWith("image", StringComparison.InvariantCultureIgnoreCase))
                    return File(Server.MapPath("~/Content/no-picture.jpg"), "image/jpg");

                using (MemoryStream output = new MemoryStream())
                {
                    db.Read(info.ID, output);

                    Image image = Image.FromStream(output);
                    Image thumbnailImage = image.GetThumbnailImage(64, 64, new Image.GetThumbnailImageAbort(delegate { return true; }), IntPtr.Zero);

                    using (MemoryStream imageStream = new MemoryStream())
                    {
                        thumbnailImage.Save(imageStream, System.Drawing.Imaging.ImageFormat.Png);

                        return File(imageStream.ToArray(), "image/png");
                    }
                }
            }
        }