ProcessImageController.cs
3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using AIAHighlight.Helpers;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
namespace AIAHighlight.Controllers
{
public class ProcessImageController : ApiController
{
// GET: api/ProcessImage
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET: api/ProcessImage/5
public string Get(int id)
{
return "value";
}
// POST: api/ProcessImage
[HttpPost]
public async Task<HttpResponseMessage> Post(HttpRequestMessage request)
{
var httpRequest = HttpContext.Current.Request;
Stream requestStream = await request.Content.ReadAsStreamAsync();
HttpResponseMessage result = null;
IEnumerable<string> layerNumberHeaderValue = request.Headers.GetValues("layerNumber");
var layerNumber = layerNumberHeaderValue.FirstOrDefault();
IEnumerable<string> bodyViewIndexHeaderValue = request.Headers.GetValues("bodyViewIndex");
var bodyViewIndex = bodyViewIndexHeaderValue.FirstOrDefault();
IEnumerable<string> bodyRegionHeaderValue = request.Headers.GetValues("bodyRegion");
var bodyRegionId = bodyRegionHeaderValue.FirstOrDefault();
if (requestStream != null)
{
string fileName = "BodyView" + bodyViewIndex + "_layer" + layerNumber + "_bodyRegionId" + bodyRegionId;
// string filePath = "D:\\ADAM\\100-PROJECTS\\001-AIAHighlight.FileSave\\AIAHighlight.Serevr\\AIAHighlight\\data1\\75\\" + fileName + ".json";
string filePath = "D:\\100-PROJECTS\\008-AIAHighlight.FileSave\\AIAHighlight\\AIAHighlight\\data1\\75\\" + fileName + ".json";
try
{
using (FileStream fileStream = System.IO.File.Create(filePath, (int)requestStream.Length))
{
// Fill the bytes[] array with the stream data
byte[] bytesInStream = new byte[requestStream.Length];
// string response1 = (JsonConvert.SerializeObject(bytesInStream));
requestStream.Read(bytesInStream, 0, (int)bytesInStream.Length);
// Use FileStream object to write to the specified file
fileStream.Write(bytesInStream, 0, bytesInStream.Length);
result = Request.CreateResponse(HttpStatusCode.Created, "TEMP.txt");
}
return result;
}
catch (HttpException ex)
{
return result = Request.CreateResponse(HttpStatusCode.BadGateway, "Http Exception Come" + ex.Message);
}
catch (Exception ex)
{
return result = Request.CreateResponse(HttpStatusCode.BadGateway, "Http Exception Come" + ex.Message);
}
}
return result; ;
}
//public HttpResponseMessage Post([FromBody]JObject image)
//{
// dynamic response = new ProcessImageHelper().writeFile(image);
// return new HttpResponseMessage { StatusCode = HttpStatusCode.Created, Content = new StringContent(JsonConvert.SerializeObject(response)) };
//}
// PUT: api/ProcessImage/5
//public void Put(int id, [FromBody]string value)
//{
//}
//// DELETE: api/ProcessImage/5
//public void Delete(int id)
//{
//}
}
}