ImageResizer is not resizing images served by WebAPI

爱⌒轻易说出口 提交于 2019-12-24 17:25:57

问题


I am trying to get ImageResizer to resize images which are served by WebAPI. I have ImageResizer installed as in documentation. /resizer.debug.ashx shows no issues. When I try to resize static image, it works fine.

I tried resizing with these parameters:

    /api/files/image/image.jpg?width=100
    /api/files/image/image.jpg?width=100&process=always
    /api/files/image/image.jpg?width=100&format=jpg

My WebAPI action looks like this:

    [HttpGet]
    public HttpResponseMessage Image(string name)
    {
        var filePath = GetFilePath();

        var response = new HttpResponseMessage(HttpStatusCode.OK);
        response.Content = new StreamContent(new FileStream(filePath, FileMode.Open, FileAccess.Read));
        response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("inline");
        response.Content.Headers.ContentDisposition.FileName = fileData.OriginalFileName;
        response.Content.Headers.ContentLength = fileData.ContentLength;
        response.Content.Headers.ContentType = new MediaTypeHeaderValue(fileData.MediaType);

        return response;
    }

Is there a way to use ImageResizer with WebAPI?


回答1:


WebAPI, MVC, and HTTPHandlers all have one thing in common - terrible file serving performance. Application frameworks, by design, aren't tuned for large file handling.

Also, due to ASP.NET and IIS pipeline limitations, you can't efficiently cache and serve images when the file is being produced by an HttpHandler/MVC/WebAPI during the ExecuteRequest phase.

Please read the ImageResizer Best Practices Guide for more information.

If you need to provide source images, you can implement IVirtualImageProvider or use one of the provided plugins to access your data store of choice.



来源:https://stackoverflow.com/questions/22165718/imageresizer-is-not-resizing-images-served-by-webapi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!