[HttpGet]
public HttpResponseMessage GetImage()
{
//文件路径
var path = HostingEnvironment.MapPath("~/App_Data/5.jpg");
FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
Image img = Image.FromStream(fileStream);
MemoryStream ms = new MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
result.Content = new ByteArrayContent(ms.ToArray());
result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpg");
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = "5.jpg"//文件名
};
return result;
}
相关