Hi,
I am build a web api cors, i have a <img src="http://localhost:89/api/file/{id}" />, you can see the src attribute which invoke a get method of FileController.
I tried to the code as below, it doesn't work. Please, give some resolve. Thanks !
public class FileController : ApiController { [HttpGet] [Route("api/file/{id}")] public HttpResponseMessage Get([FromUri] Int64 id) { var f = Repository.File.SingleOrDefault(x => x.Id == id); var fileManager = new FileManager(); var fileStream = fileManager.Open(f.FileName); var response = new HttpResponseMessage(); response.Content = new StreamContent(fileStream); // this file stream will be closed by lower layers of web api for you once the response is completed. response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment"); response.Content.Headers.ContentType = new MediaTypeHeaderValue(f.FileType); return response; } }