ImageResizer不是通过调整服务的WebAPI图像 [英] ImageResizer is not resizing images served by WebAPI
问题描述
我想获得 ImageResizer 来调整这是由供应的WebAPI的图像。我ImageResizer在文件安装。 /resizer.debug.ashx表示没有问题。当我尝试调整静止图像,它工作正常。
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
我的WebAPI动作看起来是这样的:
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;
}
有没有办法使用ImageResizer用的WebAPI的方式?
Is there a way to use ImageResizer with WebAPI?
推荐答案
的WebAPI,MVC和HttpHandlers的都有一个共同点 - 可怕的文件服务性能。应用程序框架,在设计上,不调整为大文件处理。
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.
此外,由于ASP.NET和IIS管道的限制,你不能有效地高速缓存和当通过一个HttpHandler / MVC /的WebAPI在ExecuteRequest阶段正在生产的文件提供图片。
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.
请阅读 ImageResizer最佳实践指南了解详情。
如果您需要提供源图像,可以实现IVirtualImageProvider或使用所提供的插件来访问您选择的数据存储。
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.
这篇关于ImageResizer不是通过调整服务的WebAPI图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!