public ActionResult Download(string name, string path) { var file = new BlobFile2(User.Identity.Name, path + name); if (file.Exists() && !file.IsDirectory()) { if (name != null) { Response.StatusCode = 200; Response.ContentType = file.ContentType(); Response.AppendHeader("Content-Disposition", "attachment; filename=" + name); file.GetBlob().DownloadToStream(Response.OutputStream); } else { DateTime dt; if (DateTime.TryParse(Request.Headers["If-Modified-Since"], out dt) && (file.LastModified() - DateTime.SpecifyKind(dt.ToUniversalTime(), DateTimeKind.Utc)).TotalSeconds < 1.0) { Response.StatusCode = 304; return new EmptyResult(); } Response.Cache.SetCacheability(HttpCacheability.Public); Response.Cache.SetValidUntilExpires(true); Response.Cache.SetMaxAge(TimeSpan.FromSeconds(300)); Response.Expires = 300; Response.ContentType = file.Properties().ContentType; file.GetBlob().DownloadToStream(Response.OutputStream); } } else { Response.StatusCode = 404; } return new EmptyResult(); }
public ActionResult Thumb(string path) { var file = new BlobFile2(User.Identity.Name, path); if (file.Exists() && !file.IsDirectory()) { DateTime dt; if (DateTime.TryParse(Request.Headers["If-Modified-Since"], out dt) && (file.LastModified() - DateTime.SpecifyKind(dt.ToUniversalTime(), DateTimeKind.Utc)).TotalSeconds < 1.0) { Response.StatusCode = 304; return new EmptyResult(); } Response.Cache.SetCacheability(HttpCacheability.Public); Response.Cache.SetValidUntilExpires(true); Response.Cache.SetMaxAge(TimeSpan.FromSeconds(300)); Response.Expires = 300; Response.ContentType = MimeMapping.GetMimeMapping(path); Image image = Image.FromStream(file.GetBlob().OpenRead()); new Bitmap(image, new Size(200, (int)(image.Height*200.0/image.Width))).Save(Response.OutputStream, image.RawFormat); } else { Response.StatusCode = 404; } return new EmptyResult(); }
public ActionResult UpdateText(String content, string name, string path) { try { var f = new BlobFile2(User.Identity.Name, path + "/" + name); var stream = new MemoryStream(); var writer = new StreamWriter(stream); writer.Write(content); writer.Flush(); stream.Position = 0; f.GetBlob().UploadFromStream(stream); return Json(new { code = 0 }); } catch (Exception ex) { return Json(new { code = 1, data = ex.Message }); } }