Advertisement
afterlife88

Untitled

Oct 19th, 2015
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.68 KB | None | 0 0
  1.         [HttpGet]
  2.         [Route("api/books/picture/{id}")]
  3.         public HttpResponseMessage GetPicture(int id)
  4.         {
  5.             var data = _repository.Get(id);
  6.             if (data != null)
  7.             {
  8.                 byte[] imgData = data.ImageOfBook;
  9.                 MemoryStream ms = new MemoryStream(imgData);
  10.                 HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StreamContent(ms) };
  11.                 response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
  12.                 return response;
  13.             }
  14.             return Request.CreateResponse(HttpStatusCode.NotFound, "Not Found");
  15.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement