我想从服务器下载图像并在浏览器中显示它们。但是当我在浏览器中输入 url (localhost:port/api/service/imageID) 时,会出现下载框,询问我是保存还是打开图像。但我希望图像直接显示在浏览器中。这是我的控制器“获取”方法:
public HttpResponseMessage Get(int id)
{
HttpResponseMessage response;
var image = _repository.RetrieveImage(id);
if (image == null)
{
response = new HttpResponseMessage(HttpStatusCode.NotFound);
}
else
{
response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StreamContent(new MemoryStream(image.ImageData));
response.Content = new ByteArrayContent(image.ImageData);
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentDisposition.FileName = image.OriginalFileName;
response.Content.Headers.ContentType = new MediaTypeHeaderValue(image.Mime);
response.Content.Headers.ContentLength = image.ImageData.Length;
}
return response;
非常感谢您的帮助