I need your opinion about my practice,. I want to improve it.
The requirements are the following:
- RESTFUL + OWIN (SelfHosted)
- Endpoint - Upload a file asynchronously
- Make a request to the endpoint from Postman
Well, This is what I got
For the OWIN selfhosted I followed the Microsoft Documentation
Endpoint:
FileController.cs
[HttpPost]
[Route("api/v1/upload")]
public HttpResponseMessage Post([FromUri]string filename)
{
var task = this.Request.Content.ReadAsStreamAsync();
task.Wait();
Stream requestStream = task.Result;
try
{
Stream fileStream = File.Create("./" + filename);
requestStream.CopyTo(fileStream);
fileStream.Close();
requestStream.Close();
}
catch (IOException)
{
throw new HttpResponseException( HttpStatusCode.InternalServerError);
}
HttpResponseMessage response = new HttpResponseMessage();
response.StatusCode = HttpStatusCode.Created;
return response;
}
Postman:
The postman returns Status Code 201
Some feedback please
Regards.