public async Task<HttpResponseMessage> Get(string diagramid, string imagename)
{
//Get the current authenticated user
string UserId = UserHelper.GetCurrentUserID();
//string UserId = "[email protected]";
string DiagramId = diagramid.ToLower();
string ImageName = imagename.ToLower();
string Blobname = UserId + "/" + DiagramId + "/" + imagename;
try
{
if (BlobManager.ImageExists(Blobname))
{
MemoryStream ImageStream = await BlobManager.DownloadImageAsync(Blobname);
var response = Request.CreateResponse(HttpStatusCode.OK);
response.Content = new ByteArrayContent(ImageStream.ToArray());
///TO DO: implement different image types
response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
response.Content.Headers.ContentLength = ImageStream.Length;
return response;
}
else //Image cannot be found
{
var response = Request.CreateErrorResponse(HttpStatusCode.NotFound, "'" + imagename + "' image cannot be found");
//response.Content = new StringContent("'" + imagename + "' image cannot be found");
response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
//response.StatusCode = HttpStatusCode.NotFound;
throw new HttpResponseException(response);
}
}
catch (Exception Ex)
{
string Err = string.Format("Unable to download the image {0}", imagename);
var response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, Err);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
Log.LogError("ImageAPI: Unable to download image {0}, Error: {1}", imagename, Ex.Message);
throw new HttpResponseException(response);
}
}