protected object PostBlocks(string scannerId) { HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"]; context.Response.BufferOutput = false; { HttpRequestBase request = GetHttpRequest(); byte[] data = null; String imageType = null; if (request.Files.Count > 0) { using (var stream = request.Files[0].InputStream) { using (var br = new BinaryReader(stream)) { if (br.BaseStream.Length < Int32.MaxValue) { imageType = request.Files[0].ContentType; data = new byte[br.BaseStream.Length]; br.Read(data, 0, (int)br.BaseStream.Length); } } } } if (null != data) { String blockId = TokenProvider.getInstance().takeUUID(); DbImageBlock imageBlockInfo = new DbImageBlock(); imageBlockInfo.blockId = blockId; imageBlockInfo.imageType = imageType; imageBlockInfo.data = data; imageBlockInfo.scannerId = scannerId; db.DbImageBlocks.Add(imageBlockInfo); db.SaveChanges(); String root = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority); String imageBlockUrl = String.Format("{0}/api/imageblock/{1}", root, blockId); context.Response.Write(imageBlockUrl); } } context.Response.Flush(); context.Response.Close(); return(null); }
// response user token public string Post() { { HttpRequestBase request = GetHttpRequest(); byte[] data = null; String imageType = null; if (request.Files.Count > 0) { using (var stream = request.Files[0].InputStream) { using (var br = new BinaryReader(stream)) { if (br.BaseStream.Length < Int32.MaxValue) { imageType = request.Files[0].ContentType; data = new byte[br.BaseStream.Length]; br.Read(data, 0, (int)br.BaseStream.Length); } } } } if (null != data) { String blockId = TokenProvider.getInstance().takeUUID(); DbImageBlock imageBlockInfo = new DbImageBlock(); imageBlockInfo.blockId = blockId; imageBlockInfo.imageType = imageType; imageBlockInfo.data = data; db.DbImageBlocks.Add(imageBlockInfo); db.SaveChanges(); return(blockId); } } return(""); }