In our Angular front end, we would like to provide a link that returns a PDF file. We are currently returning a RemoteStreamContent:
return new RemoteStreamContent(stream, "Report.pdf", MimeTypes.Application.Pdf);
This always returns a response with the Content-Disposition header set to "attachment", causing the browser to download the file rather than view it inline in the current browser tab.
What is the recommended way of returning a file response like this with the Content-Disposition set to "inline"?
Some options considered:
- Implementing a middleware that sets/updates the Content-Disposition header for certain API calls
- Implementing our own custom controller
Neither of these options seem ideal, as it would be preferable to have this logic encapsulated in the application service method that returns the response.
2 Answer(s)
- 
    0Hi, What is the recommended way of returning a file response like this with the Content-Disposition set to "inline"? You can create a custom controller as you said (override the default appservice to httpapi controller) and set the response header, for example: public class MyAppServiceController : AbpControllerBase, IMyAppService { [HttpGet("data/{reportId}")] public virtual async Task<IRemoteStreamContent> GetReportAsync(Guid reportId) { Response.Headers.Add("Content-Disposition", "inline"); return new RemoteStreamContent(stream, "Report.pdf", MimeTypes.Application.Pdf); } }You just need to add a line like above ( Response.Headers.Add("Content-Disposition", "inline");). You can create your controllers in the httpapi project. This is a common practise that we also follow and use some of our modules.Regards. 
- 
    0Sounds good. It would be a nice enhancement if there was a ContentDisposition property on RemoteStreamContent to allow this to be done in the application service. Thanks! 
 
                                