How to set response filename without forcing saveas dialog

I am returning a stream in some response setting the appropriate content-type header. The behavior i'm looking for is this:

  • If the browser is able to render content of the given content-type then it should display it in the browser window.

  • If the browser doesn't know how to render the content then it should display the saveas dialog where the filename should be one provided in the response.

  • The problem that if i set the Content-Disposition header with:

    "attachment; filename="myfile.txt""

    the browser will always display the savesas dialog.

    If i don't set the Content-Disposition the filename used in the saveas dialog is the one in the url that doesn't work in my case.

    I also tried setting the Content-Disposition to inline but the outcome is the same.


    正确的方法可能是:

    Content-Disposition: inline; filename="myfile.txt"


    I'm not sure if that's possible by default. By security concerns, browser doesn't send all content-types it can handle, but just a few Accept-Encoding , which doesn't help a lot in your scenario.

    Maybe you can to ask your user what he/she prefer, and store that information in their profile.

    链接地址: http://www.djcxy.com/p/46262.html

    上一篇: 来自XMLHttpRequest的流

    下一篇: 如何设置响应文件名而不强制saveas对话框