【发布时间】:2021-07-26 16:23:33
【问题描述】:
我想从我的控制器返回图像 url。
我有一个字节数组(图片)。
我不想以 64 为基数返回。
我想退货
http://localhost:6548/image/myimage.png
我该怎么做?
我的游乐场代码 - 对我不起作用。
public HttpResponseMessage ImageLink()
{
var images = _context.Set<Image>();
var image = images.FirstOrDefault(x => x.Id == 1);
//return File(image.Data, "image/jpeg");
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
result.Content = new ByteArrayContent(image.Data);
result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
return result;
}
【问题讨论】:
-
我不清楚你的意思。你只想返回一个字符串?谷歌搜索finds examples of that。但是您的字符串是有效的 URL 吗?您如何确定该 URL?显示的代码似乎与此无关,而是返回二进制文件数据。你能澄清一下你到底想要完成什么以及为什么?