下载而不显示图像或视频文件 [英] Downloading instead of showing image or video file

查看:75
本文介绍了下载而不显示图像或视频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在localhost上托管了一个简单的html文件,我想强制Google chrome浏览器下载文件而不是打开它.同样,我在锚标记中使用了download属性,但尚不支持.

Apache Tomcat 8中是否有任何设置可以在特定文件的HTTP响应标头中添加一些内容.

 < div>< a href ="mpo.mpo"下载>图片mpo文件类型</a></div> 

解决方案

您尝试在响应中设置这些标头吗?

  response.setContentType("application/octet-stream");response.setHeader("Content-Disposition","attachment; filename = file.ext"); 

如果您实际上还没有创建任何类型的servlet/控制器来接收请求,则可能需要配置过滤器:在Tomcat中设置CORS标头

I am hosting a simple html file on localhost, I want to force google chrome browser to download file instead of opening it. For the same I've used download attribute in anchor tag, but it is not supported yet.

Is there any setting in Apache Tomcat 8 for adding some thing in HTTP response header for that particular file.

<div><a href="mpo.mpo" download>Image mpo file type</a></div>

解决方案

Did you try setting these headers in the response:

response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;filename=file.ext");

If you really haven't created any kind of servlet/controller to receive the request you might need to configure a filter: http://tomcat.apache.org/tomcat-8.0-doc/config/filter.html

You can find a lot of information here too: Set CORS header in Tomcat

这篇关于下载而不显示图像或视频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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