asp.net – ASP .Net Web API下载图像为二进制
发布时间:2020-12-15 19:10:46 所属栏目:asp.Net 来源:网络整理
导读:我想尝试使用Web API进行休息调用,但我想让响应是存储在数据库中的实际二进制映像,而不是JSON base64编码字符串。任何人都有一些指针? 更新 – 这是我最后实现: HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); result.Conte
我想尝试使用Web API进行休息调用,但我想让响应是存储在数据库中的实际二进制映像,而不是JSON base64编码字符串。任何人都有一些指针?
更新 – HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); result.Content = new StreamContent(new MemoryStream(profile.Avatar)); result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); result.Content.Headers.ContentDisposition.FileName = "avatar.png"; return result; 解决方法
您可以将响应内容设置为StreamContent对象:
var fileStream = new FileStream(path,FileMode.Open); var resp = new HttpResponseMessage() { Content = new StreamContent(fileStream) }; // Find the MIME type string mimeType = _extensions[Path.GetExtension(path)]; resp.Content.Headers.ContentType = new MediaTypeHeaderValue(mimeType); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – ASP.NET MVC FileStreamResult不能按预期工
- asp.net – 当绑定到XmlDataSource时如何编程设置Dropdownl
- asp.net-mvc – 文件“?/ Views/Position/Edit.cshtml”不能
- asp.net-mvc – 在新窗口中打开的DisplayFor DataType.Url的
- 使用Asp.Net Identity 2在AspNetUserClaims中存储用户信息有
- asp.net mvc全球化.你怎么做呢?
- 深入理解C#3.x的新特性(4):Automatically Implemented P
- asp.net-mvc – MVC.net获取枚举显示名称而不必参考枚举类型
- asp.net – Telerik RadGrid GridDataItem – 如何确定列是
- 更改ASP.NET网站管理工具连接字符串
推荐文章
站长推荐
热点阅读