如何在不强制“另存为"的情况下设置响应文件名对话 [英] How to set response filename without forcing "save as" dialog

查看:32
本文介绍了如何在不强制“另存为"的情况下设置响应文件名对话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在设置适当的 content-type 标头的某些响应中返回一个流.我正在寻找的行为是这样的:

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 "save as" dialog where the filename should be the one provided in the response.

问题是,如果我将 Content-Disposition 标头设置为:

The problem is that if I set the Content-Disposition header with:

"附件;文件名="myfile.txt""

"attachment; filename="myfile.txt""

浏览器将始终显示另存为"对话框.

the browser will always display the "save as" dialog.

如果我不设置 Content-Disposition,则另存为"对话框中使用的文件名是 URL 中在我的情况下不起作用的文件名.

If I don't set Content-Disposition, the filename used in the "save as" dialog is the one in the URL that doesn't work in my case.

我也尝试将 Content-Disposition 设置为 inline 但结果是一样的.

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

推荐答案

正确的方法可能是:

内容处置:内联;文件名="myfile.txt"

这篇关于如何在不强制“另存为"的情况下设置响应文件名对话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆