Question

I'm currently updating an old site to use the Hot Towel framework and one of the the things the current site does is load an image using the HTTPMessageResponse. This works fine in the the old set up however on the new set up the image is not displayed and going to the URL produces...

StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.ByteArrayContent, Headers: { Content-Type: image/png }

I've had a look at the response both apps produce, and the responses from the following function match (the response is the same as above and the contents are a perfect match)...

namespace OPC.Controllers
{
    public class ImageController : Controller
    {
        public HttpResponseMessage GetImage(int imageId)
        {
            var blob = new byte[10];
            var context = new OPCEntity();
            var ImageString = context.sp_GetImageData(imageId);
            foreach (var Result in ImageString)
            {
                blob = Result.Data;
            }
            Image image;
            var ms = new MemoryStream();
            ms.Write(blob, 0, blob.Length);
            var result = new HttpResponseMessage(HttpStatusCode.OK);
            result.Content = new ByteArrayContent(ms.ToArray());
            result.Content.Headers.ContentType = new  System.Net.Http.Headers.MediaTypeHeaderValue("image/png");
            return result;
        }
    }
}

The image is set in the JS using...

image.setAttribute('src', document.location.href.match(/(^[^#]*)/)[0] + '/Image/GetImage?imageId=' + imageDetails.imageId);

Does anyone have any ideas on what I could be missing, or if anything in the Hot Towel framework could be interfering.

Many Thanks in advance.

Was it helpful?

Solution

Well I have missed something important... the fact that it should be...

public class ImageController : ApiController{}

However I have also found that the breeze web API config does conflict with the normal web API config so for the time being I've had to change BreezeWebApiConfig.cs to the following

public static class BreezeWebApiConfig {

    public static void RegisterBreezePreStart() {
      GlobalConfiguration.Configuration.Routes.MapHttpRoute(
          name: "BreezeApi",
          routeTemplate: "api/{controller}/{action}"
      );
    }

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top