filestreamresult

ASP.NET MVC FileStreamResult, fileDownloadName is not used

拈花ヽ惹草 提交于 2019-11-27 21:43:26
问题 The following returns a PDF which the browser tries to directly display inline. This works correctly. However, if I try to download the file, the download name is not "myPDF.pdf", but instead the ID in the route (myapp/controller/PDFGenerator/ID). Is it possible to set the file download name to be "myPDF.pdf"? public FileStreamResult PDFGenerator(int id) { MemoryStream ms = GeneratePDF(id); byte[] file = ms.ToArray(); MemoryStream output = new MemoryStream(); output.Write(file, 0, file.Length

ASP.NET MVC FileStreamResult not working as intended

白昼怎懂夜的黑 提交于 2019-11-27 15:38:00
问题 I have the following code which I stripped out of any non-essential lines to leave the minimun reproducable case. What I expect is for it to return the image, but it doesn't. As far as I can see it returns an empty file: public ActionResult Thumbnail(int id) { var question = GetQuestion(db, id); var image = new Bitmap(question.ImageFullPath); MemoryStream stream = new MemoryStream(); image.Save(stream, ImageFormat.Jpeg); return new FileStreamResult(stream, "image/jpeg"); } Can you identify