Beispiel #1
0
        public JsonResult Upload()
        {
            // Get custom headers
            var filename = Request.Headers["X-File-Name"];
            var type     = Request.Headers["X-File-Type"];
            var size     = Convert.ToInt32(Request.Headers["X-File-Size"]);
            var parentId = !String.IsNullOrEmpty(Request.Headers["X-File-ParentId"]) ? new Guid(Request.Headers["X-File-ParentId"]) : Guid.Empty;
            var name     = Request.Headers["X-File-DisplayName"];
            var alt      = Request.Headers["X-File-Alt"];
            var desc     = Request.Headers["X-File-Desc"];

            using (var mem = new MemoryStream()) {
                var stream = Request.InputStream;

                stream.Seek(0, SeekOrigin.Begin);
                stream.CopyTo(mem);
                mem.Position = 0;

                using (var binary = new BinaryReader(mem)) {
                    var media = new Piranha.Models.MediaFileContent()
                    {
                        ContentType = type,
                        Filename    = filename,
                        Body        = binary.ReadBytes(size)
                    };
                    var content = new Piranha.Models.Content()
                    {
                        Id            = Guid.NewGuid(),
                        ParentId      = parentId,
                        IsFolder      = false,
                        Name          = name,
                        AlternateText = alt,
                        Description   = desc
                    };
                    if (content.SaveAndPublish(media))
                    {
                        return(Get(content.Id.ToString(), false));
                    }
                }
            }
            return(Json(new {
                Success = false
            }));
        }
Beispiel #2
0
		public JsonResult Upload() {
			// Get custom headers
			var filename = Request.Headers["X-File-Name"] ;
			var type = Request.Headers["X-File-Type"] ;
			var size = Convert.ToInt32(Request.Headers["X-File-Size"]) ;
			var parentId = !String.IsNullOrEmpty(Request.Headers["X-File-ParentId"]) ? new Guid(Request.Headers["X-File-ParentId"]) : Guid.Empty ;
			var name = Request.Headers["X-File-DisplayName"] ;
			var alt = Request.Headers["X-File-Alt"] ;
			var desc = Request.Headers["X-File-Desc"] ;

			using (var mem = new MemoryStream()) {
				var stream = Request.InputStream ;

				stream.Seek(0, SeekOrigin.Begin) ;
				stream.CopyTo(mem) ;
				mem.Position = 0 ;

				using (var binary = new BinaryReader(mem)) {
					var media = new Piranha.Models.MediaFileContent() {
						ContentType = type,
						Filename = filename,
						Body = binary.ReadBytes(size)
					} ;
					var content = new Piranha.Models.Content() {
						Id = Guid.NewGuid(),
						ParentId = parentId,
						IsFolder = false,
						Name = name,
						AlternateText = alt,
						Description = desc
					} ;
					if (content.SaveAndPublish(media))
						return Get(content.Id, false) ;
				}
			}
			return Json(new {
				Success = false
			}) ;
		}