Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Add StaticFileResult #6260

Closed
davidfowl opened this issue May 12, 2017 · 13 comments
Closed

Add StaticFileResult #6260

davidfowl opened this issue May 12, 2017 · 13 comments

Comments

@davidfowl
Copy link
Member

If I want to return a static file from an MVC controller action, I basically need to replicate some of the logic of the static file server. To make this easier, it would be great if there was a static file result that rendered content from the web root.

public class MyController : Controller
{
     [HttpGet("/")]
     [Authorize]
     public IActionResult Get()
     {
         return StaticFile("index.htm");
     }
}

In the above example I'm using MVC for auth but the action result for auth'd users renders the index file.

/cc @rynowak @danroth27 @SteveSandersonMS @Eilon

@rynowak
Copy link
Member

rynowak commented May 12, 2017

@davidfowl
Copy link
Member Author

@rynowak yes, whatever the static file middleware does when it gets a file, this needs to do as well. Maybe it's just mime mapping but I haven't looked to see if that is the only delta.

@rynowak
Copy link
Member

rynowak commented May 12, 2017

We should find a way to expose and reuse that then. We don't have an O/L without a content type so it's something we could add.

@davidfowl
Copy link
Member Author

@rynowak The static file result should just encapsulate that. The mime mapping could be a service.

/cc @Tratcher for awareness

@davidfowl
Copy link
Member Author

@SteveSandersonMS
Copy link
Member

Sounds good to me.

At first I thought it might not be necessary since applications can just combine FileExtensionContentTypeProvider and FileResult in a couple of lines to get a working result, but when you add in ETags and Range requests, it's way too complex to replicate in application code.

@Tratcher
Copy link
Member

@jbagga is adding a lot of the missing functionality in #6150 (Ranges, conditionals, etc.).. The mime type lookup is one of the few missing pieces. The lookup is less critical from MVC, you're manually specifying the file name so you likely already know the mime type, it's not dynamic like it is for StaticFiles.

@sebastienros
Copy link
Member

Aside from content-type could we also be able to specify content-disposition? It's important as it lets the action define the filename as seen from the client's perspective and if the client should trigger a download popup or not.

Example:
Content-disposition: attachment;filename=reports.csv

@Tratcher
Copy link
Member

@sebastienros That's already available through FileDownloadName.

public string FileDownloadName

@sebastienros
Copy link
Member

@Tratcher great, and attachment ?

@Tratcher
Copy link
Member

Yes,

var contentDisposition = new ContentDispositionHeaderValue("attachment");

@mkArtakMSFT
Copy link
Contributor

We've moved this issue to the Backlog milestone. This means that it is not going to happen for the coming release. We will reassess the backlog following the current release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources.

@mkArtakMSFT
Copy link
Contributor

Closing this as it seems most of this work has been done:

@jbagga is adding a lot of the missing functionality in #6150 (Ranges, conditionals, etc.).. The mime type lookup is one of the few missing pieces. The lookup is less critical from MVC, you're manually specifying the file name so you likely already know the mime type, it's not dynamic like it is for StaticFiles.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants