Mvc: Should we provide an easy way to say if a file can be downloaded as attachment or shown inline?

Created on 11 Aug 2016  路  5Comments  路  Source: aspnet/Mvc

I came across the following post today: http://stackoverflow.com/questions/38897764/asp-net-core-content-disposition-attachment-inline

Currently we set the content disposition header only if a name is provided for the download file name property.
https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc.Core/Internal/FileResultExecutorBase.cs#L28

So currently if you do return File(virtualPath: "~/test.pdf", contentType: "application/pdf");, the response contains only Content-Type and _no_ Content-Disposition header. However browsers do not seem to care about the absence of the disposition header and they are anyway showing the content inline.

Question: We should probably expose a property on the file result types to mention about inline or attachment?

Most helpful comment

Please reopen this case, it's necessary and important.

All 5 comments

Closing because we are not planning to implement this.

Don't understand why this is closed. "attachment" is added when FileStreamResult/File/etc... is executed. Please give us a way to change to inline.

@MattyBoy4444 can you share more about what you're trying to do and what doesn't work?

The issue was closed because we saw very little demand for this feature, and we have to prioritize the work that we do based on the resources that we have. Unfortunately, this means we cannot resolve every issue.

The original SO post shows the use case.

I am returning a file from a WebAPI controller. The Content-Disposition header value is automatically set to "attachment". For example:

Disposition: attachment; filename="30956.pdf"; filename*=UTF-8''30956.pdf
When it is set to attachment the browser will ask to save file instead of opening it. I would like it to open it.

In short, some way to return data and set the content disposition header. In my specific use case I was generating a PDF-report dynamically and wanted it to open in browser. Because content disposition was set to "attachment" automatically the browser treated it as a download. I wanted it to open in browser.

If I use "return File()" I would have to save PDF-report as file, and would not be able to delete it. Unless I added some sort of tracking/cleanup, which is a lot of workaround for a simple header.

Please reopen this case, it's necessary and important.

Was this page helpful?
0 / 5 - 0 ratings