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 Download(Dictionary<string, string> env, string[] args) { var file = new BlobFile2(User.Identity.Name, env["path"] + args[0]); if (file.Exists()) { return SuccessWrapper(""); } else { return Error("File Not Exist"); } }
public JsonResult Cp(Dictionary<string, string> env, string[] args) { if (args.Length > 1) { var file = new BlobFile2(User.Identity.Name, env["path"] + args[0]); if (file.Exists()) { try { return SuccessWrapper(String.Format("{0} file(s) copied.", file.Copy(env["path"] + args[1]))); } catch (FileExistsException ex) { return Error(args[1] + " Already Exists"); } } return Error(args[0] + " Not Exists"); } return Error("Usage: mv [file1] [file2]"); }
public int Copy(string p) { if (_path.Contains(p)) throw new Exception("You can't copy a directory into itself"); var target = new BlobFile2(_username, p); if (target.Exists()) { if (target.IsDirectory()) { p += "/" + Path().Name(); } else { target.ValidateFileNotExist(); } } new BlobFile2(_username, p).ValidateFileNotExist(); var operations = new TableBatchOperation(); var path = new FilePath(p); if (IsDirectory()) { foreach (FileEntity i in FileTable.ExecuteQuery(PrefixQuery())) { var n = new FileEntity() { ContentType = i.ContentType, Key = Guid.NewGuid().ToString("N"), LastModified = DateTime.UtcNow, Length = i.Length, Path = i.Path.Replace(_path.Path(), path.Path()), PartitionKey = i.PartitionKey, Parent = i.Parent.Replace(_path.Path(), path.Path()), RowKey = DateTime.UtcNow.Ticks.ToString("D") + _rnd.Next(1000, 9999).ToString("D"), Type = i.Type }; operations.Add(TableOperation.Insert(n)); if (i.Type != FileEntity.Directory) _container.GetBlockBlobReference(n.Key) .StartCopyFromBlob(_container.GetBlockBlobReference(i.Key)); } } var m = new FileEntity() { ContentType = _entity.ContentType, Key = Guid.NewGuid().ToString("D"), LastModified = DateTime.UtcNow, Length = _entity.Length, Path = path.Path(), PartitionKey = _entity.PartitionKey, Parent = path.BasePath(), RowKey = DateTime.UtcNow.Ticks.ToString("N") + _rnd.Next(1000, 9999).ToString("D"), Type = _entity.Type }; if (!IsDirectory()) { _container.GetBlockBlobReference(m.Key).StartCopyFromBlob(GetBlob()); } operations.Add(TableOperation.Insert(m)); FileTable.ExecuteBatch(operations); return operations.Count; }
public int Move(string p) { if (_path.Contains(p)) throw new Exception("You can't move a directory into itself"); var target = new BlobFile2(_username, p); if (target.Exists()) { if (target.IsDirectory()) { p += "/" + Path().Name(); } else { target.ValidateFileNotExist(); } } new BlobFile2(_username, p).ValidateFileNotExist(); var operations = new TableBatchOperation(); var path = new FilePath(p); if (IsDirectory()) { foreach (FileEntity i in FileTable.ExecuteQuery(PrefixQuery())) { i.Path = i.Path.Replace(_path.Path(), path.Path()); i.Parent = i.Parent.Replace(_path.Path(), path.Path()); operations.Add(TableOperation.Replace(i)); } } _entity.Path = path.Path(); _entity.Parent = path.BasePath(); operations.Add(TableOperation.Replace(_entity)); this._path = path; FileTable.ExecuteBatch(operations); return operations.Count; }
public ActionResult Upload(HttpPostedFileBase file, string path, string[] args) { if (args.Length > 0) { var blob = new BlobFile2(User.Identity.Name, path + args[0]); if (blob.Exists()) return Error("File \"" + args[0] + "\" already exists."); try { blob.CreateFile(file.InputStream); return SuccessWrapper("Upload successfully"); } catch (Exception ex) { return Error("Upload file failed"); } } return Error("Usage: upload [filename]"); }
public ActionResult Touch(Dictionary<string, string> env, string[] args) { var file = new BlobFile2(User.Identity.Name, env["path"] + args[0]); if (!file.Exists()) { file.CreateEmptyFile(); return SuccessWrapper(String.Format("File \"{0}\" Created", args[0])); } return SuccessWrapper(String.Format("File \"{0}\" Updated", args[0])); }
public JsonResult Rm(Dictionary<string, string> env, string[] args) { if (args.Length > 0) { var file = new BlobFile2(User.Identity.Name, env["path"] + args[0]); if (file.Exists()) { return SuccessWrapper(String.Format("{0} file(s) deleted.", file.Delete())); } return Error("File Not Exist"); } return Error("Usage: rm [file]"); }
public JsonResult Mkdir(Dictionary<string, string> env, string[] args) { if (args.Length > 0) { var file = new BlobFile2(User.Identity.Name, env["path"] + args[0]); if (file.Exists()) { return Error("Directory \"" + args[0] + "\" already exists."); } else { file.CreateDirectory(); return SuccessWrapper(String.Format("Directory \"{0}\" Created", args[0])); } } return Error("Usage: mkdir [directory]"); }