Content-disposition中Attachment和inline的区别
来源:互联网 发布:制作书籍的软件 编辑:程序博客网 时间:2024/06/05 12:48
Content-disposition中Attachment和inline的区别
java web中下载文件时,我们一般设置 Content-Disposition 告诉浏览器下载文件的名称,是否在浏览器中内嵌显示.
Content-disposition: inline; filename=foobar.pdf
表示浏览器内嵌显示一个文件
Content-disposition: attachment; filename=foobar.pdf
表示会下载文件,如火狐浏览器中
spring mvc中
@ResponseBody @RequestMapping(value = "/download",produces="application/octet-stream") public byte[] downloadFile(HttpServletRequest request, HttpServletResponse response,String contentType2) throws IOException { byte[]bytes=FileUtils.getBytes4File("D:\\Temp\\cc.jpg"); response.addHeader("Content-Disposition", "inline;filename=\"a.jpg\""); return bytes; }
如上代码中是内嵌显示图片呢?还是会弹框下载呢?
答案是:弹框下载
为什么呢?设置为inline应该是内嵌显示啊!
因为response content type设置成了"application/octet-stream"
注意:我们说是内嵌显示还是下载,那 一定是针对可内嵌显示的类型 ,例如"image/jpeg","image/png"等.
看下面的例子:设置response content type为" image/jpeg "
@ResponseBody @RequestMapping(value = "/download",produces="image/jpeg") public byte[] downloadFile(HttpServletRequest request, HttpServletResponse response,String contentType2,String downloadType) throws IOException { byte[]bytes=FileUtils.getBytes4File("D:\\Temp\\cc.jpg"); response.addHeader("Content-Disposition", downloadType+";filename=\"a.jpg\""); return bytes; }
在浏览器中访问:http://localhost:8080/tv_mobile/video/download?downloadType=inline 时就内嵌显示:
当在浏览器中访问:http://localhost:8080/tv_mobile/video/download?downloadType=attachment 时就弹框下载.
0 0
- Content-disposition中Attachment和inline的区别
- Content-disposition中Attachment和inline的区别
- Content-disposition中Attachment和inline的区别
- Content-disposition中Attachment和inline的区别、ContentType设置
- Content-disposition中Attachment和inline的区别
- Content-disposition中Attachment和inline的区别
- 文件上传Content-disposition中Attachment和inline的区别
- Java在上传或下载时header中Content-Disposition的作用以及Content-disposition中Attachment和inline的区别
- attachment和inline的区别
- attachment和inline的区别 下载文件
- Content-disposition","attachment; filename=中文名 乱码
- header中Content-Disposition的作用
- header中Content-Disposition的作用
- header中Content-Disposition的作用
- header中Content-Disposition的作用
- header中Content-Disposition的作用
- header中Content-Disposition的作用
- header中Content-Disposition的作用
- CodeForces--626C--Block Towers (二分)
- scatter简单应用
- android 开发技巧(10)--为背景添加圆角边框
- Tomcat 7.0.50 Coyote 连接器类结构和架构设计简析
- UML建模教程
- Content-disposition中Attachment和inline的区别
- SVN:Errors running builder 'DeploymentBuilder' on project---谷营中西软件科技园
- WEB安全之Token浅谈
- Android CM12.1 关机流程
- 让所有习惯黑暗的眼睛,都习惯光明。——顾城
- Java中多态的粗浅见解
- 使用adb命令查看apk包名信息
- git图解原理
- PEB进程环境块分析研究