ASP.NET Core 2.0 Return stream
-
I have worked with the samples from the video and all are working fine. I now want to return a stream now....here's my code based on the way I think it should work. Unfortunately I get an exception. JsReportBinaryException: Error rendering report: rendering has finished with errors:
Here's my code in my Controller( I've taken my example from the video and it's a simple test instead of using File.Create I am returning a stream)[MiddlewareFilter(typeof(JsReportPipeline))] public async Task<IActionResult> ReportContentReturnAsync() { var rs = new LocalReporting().UseBinary(JsReportBinary.GetBinary()).AsUtility().Create(); var report = await rs.RenderAsync(new RenderRequest() { Template = new Template() { Recipe = Recipe.PhantomPdf, Engine = Engine.None, Content = "Hello from pdf" } }); var memoryStream = new MemoryStream(); await report.Content.CopyToAsync(memoryStream); memoryStream.Seek(0, SeekOrigin.Begin); return new FileStreamResult(memoryStream, "application/pdf") { FileDownloadName = "out.pdf" }; }
-
Try to remove the
[MiddlewareFilter(typeof(JsReportPipeline))]
. That line instructs the asp.net core integration to run the report rendering based on the output of the action. That is what you don't want here.
-
Yes removing the MiddlewareFilter fixed this issue. I just wanted to say thank you for producing such a great product!
-
Great. You are welcome!