设置内联文件标题?

Alb*_*elB 5 html filenames http-headers

我强迫下载到浏览器的文件头部中设置进行处理Content-disposition,以inline;

有没有这样设置标题的方法?当前,看起来浏览器会自动使用文件的URL填充它。

Tra*_*May 7

是可以的,只要让你的URL末尾包含文件名,一定要对其进行URLEncode,大多数浏览器会忽略queryString

本地主机:3000/blah/blah/blah/Attachment%3A%20Screen%20Shot.png/?id=1670674338147205293

选项卡显示=“附件:屏幕截图.png”

在 Chrome、Firefox 和 Opera 上运行良好。。。Safari 根据您的设置显示域名或整个 URL


Thi*_*ter 2

是的,您可以像为 那样指定文件名content-disposition: attachment,即如下所示:

Content-disposition: inline; filename="foo.bar"
Run Code Online (Sandbox Code Playgroud)

有关此标头的一些有用信息,请参阅这篇文章:How to Encode the filenameparameter of Content-Disposition header in HTTP?

  • 当将其设置为“inline;”时,这似乎不起作用通过 POST 加载文件后,这是我的“Content-disposition”标头:“Content-disposition:inline;” filename="foo.bar"` 页面的标题仍然设置为 `localhost:3000/blah/blah/blah` 如果我尝试保存文件,文件名已设置,但我希望设置选项卡的标题。 (9认同)
  • 啊,那是不可能的。文件在浏览器中没有标题。 (3认同)