希望有一个高效的ASP.NET Web API控制器能够可靠地回到30〜50〜3MB JPEG文件 [英] Want an efficient ASP.NET Web API controller that can reliably return 30 to 50 ~3MB JPEGs

查看:130
本文介绍了希望有一个高效的ASP.NET Web API控制器能够可靠地回到30〜50〜3MB JPEG文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改以下code成一个高效的Web API控制器的方法,可以返回30〜50 JPEG文件(对于小于20个用户同时使用)平均3MB大小的

I'd like to change the following code into an efficient Web API controller method that can return 30 to 50 JPEGs (for <20 simultaneous users) of average 3MB size.

    public async Task<HttpResponseMessage> Get(int imageid) {
        return await Task.Run(() => {
            var dzImage = _dataContext.DeepZoomImages.SingleOrDefault(_ => _.ImageID == imageid);
            if (dzImage == default(DeepZoomImage)) {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
            }
            var response = new HttpResponseMessage(HttpStatusCode.OK);
            var bitmap = GetFullSizeBitmap(dzImage);
            var memoryStream = new MemoryStream();
            bitmap.Save(memoryStream, ImageFormat.Jpeg);
            response.Content = new ByteArrayContent(memoryStream.ToArray());
            var fileName = string.Format("{0}.jpg", dzImage.ImageName);
            response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = fileName };
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
            memoryStream.Flush();
            return response;
        });
    }

上述方法处理一个图像。我怎样才能最好的复数它来有效地处理多个图像的这种用法/负载的情况?是否有可能返回任务&LT; Htt的presponseMessage&GT; []或[任务和LT; Htt的presponseMessage []&GT;

The foregoing method handles one image. How can I best pluralize it to handle multiple images efficiently for this usage/load scenario? Is it possible to return Task<HttpResponseMessage>[] or Task<HttpResponseMessage[]>?

或者倒不如产生的所有图像和一次性归还?

Or would it be better generate all images and return them in one go?

感谢您的帮助...

推荐答案

根据我们的讨论最好的方法这里将是在服务器上创建一个ZIP文件,然后下载一个文件给用户。作为一种替代方法,你可以试试这个多文件下载方法。

Based on our discussion the best approach here would be to create a ZIP file on the server and then download that one file to the user. As an alternative you could try this multi-file download approach.

这篇关于希望有一个高效的ASP.NET Web API控制器能够可靠地回到30〜50〜3MB JPEG文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆